Hello,
On Mon, Apr 28, 2014 at 4:00 AM, Peter Hug
<
pete...@warehouseoptimization.com> wrote:
[...]
>>
>> Exactly, however your proposal has a problem: it contradicts JSON
>> Reference. You are supposed to ignore other fields other than "$ref"
>> when processing one ;)
>
> If we added a new keyword we could also change some rules :).
>
Not that one! JSON Reference is not defined by JSON Schema; if we use
it, we must obey its rules ;)
> While I see
> some good things in your "merge" and Christopher's $patch keyword, they
> don't give me what I'm after.
>
And what exactly are you after?
> {
> $inherits: {$ref: #/definitions/recipe},
> title: baking,
> descriptions: recipes for items you'd typically find in a bakery,
> properties: {
> preheat: {},
> backing: {},
> fan: {},
> heating: { type: string, enum: [upper, lower, both] }
> }
> }
>
> (Note that a $ref keyword, if specified, would still take precedence and all
> else in here would be ignored.)
>
> $inherits could be a schema or an array of schemas (allowing to inherit from
> multiple sources).
>
I fail to see how you can _not_ do this with "$patch"?
> I think the tricky bit is to define the rules. Some that spring to my mind
> are:
>
> 1. the type of schema referenced in $inherits must be "object"
> 2. specify all schema keywords which are not inherited (e.g.
> additionalProperties, ...)
> 3. specify all schema keywords which are prohibited in association with
> $inherits (e.g. type, ...)
> 4. specify properties which can be overridden (e.g.: title, description,
> ...)
> 5. specify properties which are merged or combined (e.g. properties,
> requires, ...)
> 6. properties must be unique, i.e. you can neither $inherits from A and B
> when both specify property X nor can you specify a property in the schema's
> properties property which matches an inherited property
>
> I can't see how we could add such a feature without defining strict rules.
> Admittedly it will make the process of writing these specifications a whole
> lot more difficult and time consuming, but simply leaving these out
> altogether is not the answer, is it?
>
As you say, it is too complex. And this will lead people to thinking
that JSON Schema is just about JSON Objects whereas it isn't. JSON-LD
and friends all share that common pitfall. Let us not go there!
At least, "$patch" and "$merge" rules are simple ;)