This is draft version 2. The current draft is version 3.
> {
> "state":
> {
> "optional":true
> },
> "town":
> {
> "requires":"state",
> "optional":true
> }
> }
>
> I can not understand, is it possible to do the following:
>
> 1) field "town" required only if "state" is "California" else "town" is
> optional.
>
This is one way to do it:
{
"notCalifornia": {
"properties": {
"state": {
"disallow": [ { "enum":[ "California" ] } ],
"type": "string"
},
"town": { "type": "string" }
}
},
"California": {
"properties": {
"state": { "enum":[ "California" ] },
"town": { "type": "string" },
"dependencies": {
"state": "town"
}
}
},
"type": [
{ "$ref": "#/notCalifornia" },
{ "$ref": "#/California" }
]
}
> 2) two types validation of one field. I mean boolean and int array.
> This field can be implemented with enum [true,false,1,2,3,4,...].
> But this way doesn't validate type of field and value isn't array. Can I do
> it differently?
>
Your enum won't work, as enum is a list of values which the instance
must match exactly. In your example, your instance must have either
value true, or false, or 1, or... etc.
It isn't really clear what you want. If you mean that your instance is
either a boolean or an array of integers, then you can write:
{
"type": [ "boolean", "array" ],
"items": { "type": "integer" }
}
If you want your instance to be an array which elements are either
integers or booleans, then this would be:
{
"type": "array",
"items": { "type": [ "boolean", "integer" ] }
}
--
Francis Galiegue,
fgal...@gmail.com
"It seems obvious [...] that at least some 'business intelligence'
tools invest so much intelligence on the business side that they have
nothing left for generating SQL queries" (Stéphane Faroult, in "The
Art of SQL", ISBN 0-596-00894-5)