sunlightlabs/validictory — Issue #12: How to test an array with N items that validate against M schemas
Author: JasonSanford
Created: 2011-12-02 07:15:00+00:00
State: open

I'm trying to validate an array that can have any number of items in it. Each of these items can be one of 5 or 6 schemas. So, for example:

schemaPoint = {
"type": "object",
"properties": {
"type": {
"pattern": "Point"
},
"coordinates": {
"type": "array"
"items": {
"type": "array",
"minItems": 2,
"maxItems": 3
}
}
}
}

schemaLineString = {
"type": "object",
"properties": {
"type": {
"pattern": "LineString"
},
"coordinates": {
"type": "array",
"minItems": 2,
"items": {
"type": "array",
"minItems": 2,
"maxItems": 3
}
}
}
}

There are a number of other schemas, but I'm omitting them for brevity.

So, what I need to do is create a GeometryCollection schema that has a ```geometries``` property that is an array. This array should contain items like ```schemaPoint```, ```schemaLineString``` and quite a few others I've not shown here.

My first attempt is something like the following:

schemaGeometryCollection = {
"type": "object",
"properties": {
"type": {
"pattern": "GeometryCollection"
},
"geometries": {
"type": "array",
"items": [schemaPoint, schemaLineString]
}
}
}

Essentially what I want in the above is for the ```geometries``` array above to have any number of items in it, so long as each of those items matches either ```schemaPoint``` or ```schemaLineString```.

Am I making any sense?