Hello!
I've already mentioned this problem as a sidenote on this mailling-list, but now that I've implemented and used it, I'd like to throw it into discussion.
In Order to have a DRY model, I was re-using JSON Schemas a lot. This can be done via the $ref attribute, but the official JSON Schema Specification does not define if there is inheritance behaviour. (and if, how).
Inheritance behaviour made a lot of sense to me, since I can inherit attributes and still overwrite them. In my own (prototype) implementation I've introduced a $extend attribute that does exactly that: It makes a deep copy of the current scope of the $extend copy and merges it with the referenced $extend object.
I'll make an example:
An abstract Shape Model:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Shape",
"description": "Generic Shape",
"type": "object",
"properties": {
"x": {
"type": "integer"
},
"y": {
"type": "integer"
}
},
"required": ["x", "y"],
"abstract": true
}
Then there's a Circle, that extends from Shape:
{
"$extend": "/model/_Shape.json",
"title": "Circle",
"type": "object",
"properties": {
"radius": { "$extend": "/field/radius.json" },
},
"required": ["x", "y", "radius"],
"abstract": false
}
So, the properties x and y are inherited. The title is overwritten. The property radius is also $extended, so properties can be reused between different models.
I hope you get the idea.
So here's my question: Would it make sense to have the spec define if and how inheritance should be implemented? I've noticed that some implementations (I think it was t4v) was actually doing inheritance with $ref. But this is nothing the spec talks about, so I can't count that this behaviour is consistent through different implementations. Since I wasn't doing something official, I decided to implement my own $extend attribute and the inheritance logic behind it.
And there's the naming thing. I also read of a $merge attribute, but didn't found much informations about it.
Feel free to tell me what you think of it, if that makes sense to you.
If you're insterested in the background of this, I've created a project called "mobo" that uses JSON Schema for Graph Data Model Generation in Semantic MediaWiki. The model is written in JSON Schema and the Model, the Forms, Documention and through Semantic MediaWiki even Semantic Attributes are automatically generated. Here's a presentation about it:
http://fannon.de/p/mobo-intro/#/
Kind Regards,
Simon