You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm an objection user, and i've implemented a 'block' schema that can be extended depending on the value of a type property, using switch 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 root properties object, or complains about properties (supposedly) inherited from the root properties object if i put it on the switch properties 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:
@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)
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: