-
-
Notifications
You must be signed in to change notification settings - Fork 873
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
additionalProperties and switch don't mix very well together #410
Comments
Using [email protected] |
@kapouer "additionalProperties" keyword only takes into account the properties and patternProperties in the same schema object, properties defines in other objects in the schema schema are not taken into account. This behaviour is per spec. The is no such thing as "inheritance" in JSON schema. The easy way to think about it is to see JSON schema as a set of restrictions that should be satisfied for the data to be valid. Each keyword applies restrictions according to strictly defined rules. While in simple cases JSON schema looks like a definition of the object structure, in general case it is not. In this way "properties" keyword does not define properties, it defines restrictions on property values if they are present in the object. So "properties" keywords defined in different places of the same schema are not supposed to be merged or treated together and "additionalProperties" keyword is not supposed to take them all into account. That follows from one important design principle of JSON schema that it is shallow and the result of validation of any keyword can only depend on sibling keywords in the same object, but not on any other keywords present anywhere else in the schema. This limitation is a known one, there are multiple discussions about how to address this problem and no clear consensus at the moment. There are several workarounds though: see #134 (comment) |
Thank you for the explanation. |
I'm an objection user, and i've implemented a 'block' schema that can be extended depending on the value of a
type
property, usingswitch
keyword: an example schema and data here.However, when i try to add
additionalProperties: false
somewhere in that schema, it either just doesn't work if i put it on the rootproperties
object, or complains about properties (supposedly) inherited from the rootproperties
object if i put it on the switchproperties
objects.It looks like there is some problem with the specification but i figured i would talk about it here before reporting anything to https://github.com/json-schema-org/json-schema-spec.
The text was updated successfully, but these errors were encountered: