In JSON Schema if we have "additionalProperties":false at the root level and "additionalProperties":true nested how are we to resolve this putative "conflict"
For example
{
"id": "someId",
"type": "object",
"additionalProperties": false,
"properties": {
"storage": {
"type": "object",
"additionalProperties": true
"properties": {
"type": { "enum": [ "disk" ] },
"device": {
"type": "string",
"pattern": "^/dev/[^/]+(/[^/]+)*$"
}
},
"required": [ "type", "device" ]
}
}
}
Does one override the other?
They don't override. Their scope is limited to the JSON schema level.
JSON Schema is a constraint system, so you can only add constraints, never remove them. If "additionalProperties": true
and "additionalProperties": false
both apply, the effect is just as if only false
were present (because it is the stricter constraint).
Furthermore, additionalProperties
only "knows" about properties
and patternProperties
within the same schema object. It cannot "see" into subschemas (inlined or referenced). So your schema above will not allow any properties.
Note that a similar keyword that can "see" into subschemas is likely to be added in draft-08, although we haven't figured out exactly how it would work. Currently, no JSON Schema keyword behaves in that manner so adding such a feature is a complex endeavor. But it's the primary goal of draft-08.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.