-
-
Notifications
You must be signed in to change notification settings - Fork 370
Description
I am experimenting a bit with JSON schema rules and was surprised about non-deterministic JSON Schema validation rules (or allowing ambiguity).
Let me use an example JSON schema that describes a document that may have just "firstName" or "firstName" and "lastName".
{
"description": "schema validating people",
"type": "object",
"oneOf": [
{
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"firstName",
"lastName"
]
},
{
"properties": {
"firstName": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"firstName"
]
}
]
}
Note: I do know that my constraints could be described in a much easier way. This is purely to give you an idea about the problem.
oneOf contains essentially the same/similar content. After detecting "firstName" one still not knows whether the first or the second branch of oneOf is correct. This could be even more complex with nesting and such...
Having said that, I wonder why JSON schema allows such ambiguity and does not forbid that.
FYI: XML schema is more strict in that sense and a similar schema with these constraints would not be valid.
Do I miss anything here?
Any thoughts?
Thanks for your feedback!