Take a look at this document:
http://groups.google.com/group/json-schema/web/json-schema-proposal-working-draft
(paragraph "Extending and Referencing"). This is the only place, where
I found a clear definition of how "extends" should be treated. At
first, I thought, that this is the easiest - and best - way to
validate extends, but after creating a real world case I found that it
is bad idea. It is about constraints. So the parent must be more
constrained than the extended schema to make this way of validating
useful. For the most cases it's OK.
Back to my problem - I have two schemas:
{
id:'A',
type:'object',
properties: {
a: {...},
b: {...}
},
additionalProperties: false,
extends: {$ref:'B'}
}
and
{
id:'B',
type:'object',
properties: {
a: {...},
c: {...}
}
}
So at first I validate an instance to schema B, additional properties
are allowed, then while validating schema A, property c is not allowed
any more. In reality, properties a, b and c should by allowed in
schema A, but because of additionalProperties: false in A, c will not
be allowed anymore.
Conclusion: It happens, that schemas contradict each other, if they
are used separately. If you overwrite (deeply extend) schema B by
schema A internally, you have a schema that has no perils. You can
still define "extends", but in the new proposal, it will be treated as
a special case. The validator is forced to build one compact schema
internally.
My main motivation is to make JSON Schema able to handle real world
cases. Take a look at my JavaScript validator:
http://github.com/akidee/schema.js
I have added features like fallbacks (for tolerant value adaptation)
and adapters. The "official" JSON Schema validators validate only in
strict mode, and I don't see any sense in this, because data from a
client is always an untrusted source and must be adapted to your
schema. Examples: 'false' => false, '1.234' => 1.234, '0' => false
My framework is the only framework that is able to handle the real
world cases, and you should use it.
It is still in development. Another problem that arises with the
current handling of "extends" is that you have less performance
because you revalidate some properties and that the error list is not
unique, when a validation fails in such a case.
It's really tricky - but challenging - to implement a JSON Schema
validator that makes sense and has got the features that are really
important. Then you can use it for any case: Another interesting
example is secure function calls - you simply proxy calls to a
function (in your API) with a JSON Schema validation and that's it.
Ready for production ;)
Final point: The current proposal and the core schema contradict to
each other. It seems that JSON Schema is not sophisticated in the
moment. But I want to make it better, because JSON is _the_ standard
for data.
On 24 Aug., 04:45, Gary Court <
gary.co...@gmail.com> wrote:
> When I was writing JSV, I was unable to come up with a solution where
> I could guarantee that I only needed to validate against the extended
> schema. And frankly, as the spec is currently written, it would be
> very difficult. There was project called jsev (
http://code.google.com/p/jsev/