I have several JSON documents that have very similar structure but differ in some nested JSON objects. I want to create a JSON schema for the common parts of the documents and separate schemas for the varying parts. For example
// schema1.json
{
"definitions": {
"field": {
"id": "field-schema",
"type": "string"
}
},
"$ref" : "common.json"
}
// schema2.json
{
"definitions": {
"field": {
"id": "field-schema",
"type": "number"
}
},
"$ref" : "common.json"
}
// common.json
{
"type" : "object",
"properties": {
"field": {
"$ref": "field-schema" // ERROR: ref not found
}, ...
}
}
schema1.json and schema2.json reference the common schema (common.json) and define specific schemas (kind of like template method pattern). The example does not work. Is this implementation dependent? Is there a way to accomplish this without any preprocessing?