How do i use $ref in this , what is the use of link ? how will these
get resolved in validation ? Even if there are no right answers for
this right now , but my guess is that this definitely worth looking
at .
While I cannot answer everything because I don't know XSD (which, for
me, has been written by someone on drugs but that's another story), I
can give you the general principles.
A "fully qualified" schema, for lack of a better name, is always a
JSON object, and has the following elements always defined:
{
"$schema": "http://path.to/schema/version#",
"id": "http://location.of/this/schema#",
// etc -- more on this # later
}
where:
* "$schema" is an URI indicating that this schema is written with this
version; the URI points itself to a schema, which validates itself,
and the current schema;
* "id" is where your schema is located.
$ref is used like this:
{
"$ref": "http://location.of/a/schema#/path/into/that/schema/if/necessary"
}
This is called a JSON Reference. The URI is to be separated in two parts:
* "http://location.of/a/schema" --> location of the JSON document;
* "#/path/into/that/schema/if/necessary" --> the JSON Pointer against
which to resolve the JSON document to get the schema.
The JSON Pointer for the root of a JSON document is "#", hence the "#"
in the examples above means that the whole JSON document pointed by
the resource is the schema itself.
For your use case, you'd have the choice of:
* writing only one JSON document with all schemas in it, and address
them in $ref using "non empty" JSON Pointers:
----
{
"id": "http://where.the/document/is#",
"firstschema": { ...},
"secondschema": { ... }
}
----
and then address each schema by { "$ref":
"http://where.the.document/is#/firstschema" } and so on;
* writing one JSON document per schema, putting them at different
location, and using appropriate $refs with "empty" JSON Pointers.
Please wait for more authoritative answers, I have only understood the
mechanism a few weeks ago.
Hope this helps and doesn't confuse you,
--
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)
How will i extend that property ? A very simple example would be
appreciated. Can we cover this case in the draft-specification and
hence have more clarity?
> Francis Galiegue, fgalie...@gmail.com
I am not sure if I fully understand your question, but here is an example:
* one schema that you reference:
----
{
"id": "http://some.where/sub/schema#",
"type": "object",
"properties": {
"p1": {
"type": "integer",
"minimum": 12
}
}
}
----
* the main schema:
----
{
"id": "http://path.to/base/schema#",
"type": "array",
"items": {
"extends": {
"$ref": "http://some.where/sub/schema#/properties/p1"
},
"divisibleBy": 5
}
}
----
So, what does this say about the main schema:
* that the JSON document must be an array,
* that the items in the array must obey both:
** the schema found at JSON Pointer "#/properties/p1" in the JSON
document found at "http://some.where/sub/schema#" (the fact that the
JSON document is itself a schema does not matter at all here), which
says the property should be an integer with a minimum value of 12,
** the additional constraint that this same integer must be divisible by 5.
"extends" basically says that you must obey the referenced schemas
(because there _can_ be several schemas referenced in "extends", here
there is only one), plus the additional constraints.
Hope this helps,
--
Francis Galiegue, fgal...@gmail.com