On Thu, Sep 6, 2012 at 11:46 AM, Anton Koval <
psih...@gmail.com> wrote:
> Hello, guys!
>
> Please correct me, if I understand purposes/goals of json-schema mechanism
> in a wrong way.
> Lets suggest, we have two types of object within our JSON, like:
> {foo: { is: bar } } and {bar: { contains: foo } }. Call them f1 and f2
> respectively
> Based on this two objects, some other JSON (using and/or joins ) could be
> generated:
>
> {
> or: [ f1, {and: [ f1, f2 ]}, f2 ]
> }
>
> or
>
> {
> and: [ f1, f2 ]
> }
>
> or
>
> {
> and: [f2, {or: [f2, {and: [f1, f2] } ] } ]
> }
>
> tons of variants here.
>
> Is it possible to write single json-schema for validation different
> combinations of or/and with my objects f1/f2?
> Or should I validate only f1/f2 with json-schema? And all the joins
> validate with some other mechanism (like some recursive bypass with
> validation of join conditions)?
>
It is possible. The schema is unfortunately quite complicated, since
draft v3 has no "maxProperties" (it is scheduled for addition in draft
v4):
{
"type": [ { "$ref": "#/or" }, { "$ref": "#/and" } ],
"f1": {
//schema for f1 here
},
"f2": {
// schema for f2 here
},
"array-element": {
"type": [ { "$ref": "#/f1" }, { "$ref": "#/f2" }, { "$ref":
"#/or" }, { "$ref": "#/and" } ]
},
"or": {
"type": "object",
"properties": {
"or": {
"type": "array",
"items": { "$ref": "#/array-element" }
}
},
"additionalProperties": "false"
},
"and": {
"type": "object",
"properties": {
"and": {
"type": "array",
"items": { "$ref": "#/array-element" }
}
},
"additionalProperties": "false"
}
}
If you have questions about the logic used, feel free to ask!
--
Francis Galiegue,
fgal...@gmail.com
JSON Schema:
https://github.com/json-schema
"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)