fge/json-schema-validator — Issue #1: validation of polymorphic arrays fails
Author: derammo
Created: 2011-10-19 21:49:11+00:00
State: open

A schema for a heterogeneous/polymorphic array fails to validate. Here is an example, which is the schema for an array of objects that match one of two schema versions:

{ "type" : "array",
"items" :
[
{ "type" : "object",
"properties" :
{ "a" : { "type" : "string", "required" : true },
"b" : { "type" : "string", "required" : true } }
},
{ "type" : "object",
"properties" :
{ "c" : { "type" : "string", "required" : true },
"d" : { "type" : "string", "required" : true } }
}
]
}

Here is a conformant object:

[ {"a" : "1", "b" : "2"}, {"c":"3", "d":"4"}]

validation fails with messages like "property c is required but was not found". The suspected reason is that separate schema versions are somehow collapsed internally and validation of required properties is not done separately for each schema that can match. As a result, any non-homogeneous arrays cannot contain objects with required properties.