On 10/23/2012 04:08 PM, Philipp Kewisch wrote:
> I have an array that can have any amount of elements. The schema for
> each element is not only of one kind, but of multiple. I couldn't find a
> way to do this with the -03 draft. Maybe you can help me, or consider
> this for a future draft. Example:
>
> Data:
> [
> [ "foo", {}, "bar"],
> [ "baz", {}, [1,2,3]],
> [ "foo", {}, "quux"],
> ...
> ]
>
> Requirements:
> * those arrays with first member "foo" must have a string value at the
> last element.
> * those arrays with the first member "bar" must have an array with its
> own format as the last element.
[ I don't understand that one ]
> * Lots of similar requirements with data not mentioned
>
And no constraints on the middle elements?
If it were on the first and then other elements then that would be easy
enough:
{
"case1": {
"items": [ { "enum": [ "foo" ] } ],
"additionalItems": { "type": "string" }
},
"case2": {
"items": [ { "enum": [ "bar" ] } ],
"additionalItems": { "type": "array" }
},
"type": "array",
"extends": {
"type": [ { "$ref": "#/case1" }, { "$ref": "#/case2" } ]
}
}