I have two schemas:
{
"type" : "object",
"properties" : {
"parentProperty" : {
"type" : "string",
"required" : true
}
},
"additionalProperties" : true
}
{
"type" : "object",
"extends" : {
"$ref" : "Parent.json"
},
"properties" : {
"childProperty" : {
"type" : "string",
"required" : true
}
},
"additionalProperties" : false
}
If I validate the following json string against the Child schema it fails.
{
"parentProperty" : "b41281",
"childProperty" : "ru7oj"
}
error: additional properties not permitted; unwanted: ["parentProperty"]
From what I understand this fails because the 'extends' does not merge the two schemas instead it validates
the json against the two schemas and therefore fails when validating against the Child schema.
From reading some of the comments in this forum and elsewhere it seems like 'extends' will be replaced with
'allOf' but I am not clear if that will then allow me to perform the validation I am trying to do in this example.
For the time being I am getting rid of the Parent schema and simply adding its 'parentProperty' to the Child schema.
* Note that I would like to keep schemas in separate files. In my use case I can have many 'children' for any given
'parent' and if I was to add a new property to a parent I would like to do it in one schema file.
I am hoping that someone in this forum can explain to me if the new 'allOf' (or something else) would
be able to solve this problem.
If 'allOf' is not going to help, I think I will probably get my server to automatically merge the schemas before serving
them. (ie when a request comes in for Child schema, it will inspect the schema, and if it 'extends' another schema it would
copy all properties from the Parent schema into the Child schema before returning it).