Skip to content

What about an isRequired keyword? #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sheinzle opened this issue Apr 29, 2019 · 2 comments
Closed

What about an isRequired keyword? #734

sheinzle opened this issue Apr 29, 2019 · 2 comments

Comments

@sheinzle
Copy link

sheinzle commented Apr 29, 2019

We're working on client project with a huge flat input JSON file, with > 100 entries on the top level.

In such a setting, the required keyword becomes unmaintainable: when adding a new property or renaming a property, the required-list might get forgotten. Furthermore, as schema developer, it's not so clear on first sight which properties are actually required and which are not.

As I understand, there are already long discussions on how to support a require-all #659 , but what about turning around the require approach instead? Consider the following syntax:

{
    "properties": {
        "foo": {"type": "integer", "isRequired": true},
        "bar": {"type": "integer", "isRequired": true},
        "notRequired": {"type": "integer", "isRequired": false},
        "alsoNotRequired": {"type": "integer"}
        ... 100 more entries
    }
}

This way, we don't need the required keyword.

  • Each of the properties themselves can specify if they are required.
  • Renaming a property only needs one touchpoint, not modifying two source locations.
  • It is immediately clear, if a property is required or not.
  • And it should also work when combining schemas.

Disclaimer - I'm fairly new to the JSON schema, maybe I am missing a crucial bit.

@awwright
Copy link
Member

awwright commented Apr 30, 2019 via email

@handrews
Copy link
Contributor

handrews commented Feb 5, 2020

I'm going to close this in favor of requiredProperties as explained in #846. That issue includes a detailed explanation of why a boolean keyword such as isRequired (which was actually how required worked way back in draft-03) is not possible.

@handrews handrews closed this as completed Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants