Skip to content

Schema with undefined required properties should not be valid #692

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
daniwelter opened this issue Dec 7, 2018 · 2 comments
Closed

Schema with undefined required properties should not be valid #692

daniwelter opened this issue Dec 7, 2018 · 2 comments

Comments

@daniwelter
Copy link

We have come across the following use case/bug a couple of times recently in the HCA metadata:

During schema edits, properties were removed or renamed but the update was not propagated to the required array. We therefore had properties declared as required that were not defined under properties{}.

These schemas were not flagged as invalid but as all our schemas use additionalProperties:false, no document can be successfully validated against such a schema as it would either be missing a required property or contain an undefined additional property.

We think this logical contradiction should be accounted for in the JSON Schema specification.

@handrews
Copy link
Contributor

handrews commented Dec 7, 2018

@daniwelter there are two answers here:

  1. There is a proposal to rearrange how required vs optional properties work. Please join the discussion in issue Added new "requiredProperties" keyword to supersede the "required" keyword #681 for that.

  2. This is the sort of thing that should be caught by a linter, rather than forbidden by the specification. The specification allows for many nonsensical/impossible keyword combinations to exist for a variety of reasons, including that sometimes auto-generated schemas correctly produce such combinations where the desired outcome is that nothing validates.

I'm going to close this issue in favor of #681 but please do add your use case there.

@handrews handrews closed this as completed Dec 7, 2018
@gregsdennis
Copy link
Member

@daniwelter it should also be mentioned that it's okay to say that a property is required without explicitly defining it. I would say, however, that an author SHOULD list the property with a true requirement that would make any value valid, just to be explicit.

If you or your company has a policy that all properties should be listed, then I agree with @handrews: use a linter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants