JSON Schema validation is not validating Array items when items are declared using $ref in the Schema. It allows additional properties in the object which are not present in the schema although additionalProperties is set to False in the root schema object.
Here's a sample schema json schema where you can reproduce this issue.
{
"StudentDetails": {
"$ref": "#"
},
"Student":
{
"type": "object",
"properties": {
"name": {
"description": "A link that can be used to fetch the next batch of results. The link contains an opaque continuation token.",
"nullable": "true",
"type": "string"
},
"age": {
"description": "The average rating of the title",
"type": "number",
"format": "double"
}
}
},
"type": "object",
"additionalProperties": false,
"unevaluatedItems": false,
"unevaluatedProperties": false,
"properties": {
"Students": {
"type": "array",
"items": {
"$ref": "#/Student"
}
}
}
}
And here's an example object which should ideally fail the validation, but it actually succeeds.
{
""Students"": [
{
""name"": ""X""
},
{
""age"": 20
},
{
""height"": 6
}
]
}
I expect that JSChema validation would fail saying "height" property is unevaluated.
I only see this issue with Arrays though. Any direct object validation works perfectly fine even with nested object structure.
Can someone please help me address this issue ?
I was testing out the JSchema validator for edge cases and ran into this issue where Array objects are not validated correctly.
There is no version of the JSON Schema spec that both accepts
"nullable": true(nullwas added as a possibletype), and"unevaluatedProperties": false. What implementation are you using? Regardless, it is buggy as using a$refinside anitemsis perfectly valid.