Combining schemas

56 views
Skip to first unread message

z10...@gmail.com

unread,
May 24, 2016, 1:25:05 PM5/24/16
to JSON Schema
Hello,

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?

Roy Walmsley

unread,
May 24, 2016, 4:07:03 PM5/24/16
to JSON Schema, z10...@gmail.com
I can see that your first two definitions have defined "field". "field-schema" is a property within this definition, and not externally directly referenceable. If you want to reference "field-schema" you need to have a separate definition for "field-schema".
Reply all
Reply to author
Forward
0 new messages