This is a snippet of my schema
"definitions" : {
"base" : {
"type" : "object",
"properties" : {
"variable" : { "type" : "string" },
"name" : { "type" : "string" },
"visible" : { "type" : "boolean" },
"type" : { "type" : "string" }
},
"required" : ["variable","name","visible","type"]
},
"expression_field" : {
"allOf" : [
{ "$ref" : "#/definitions/base"},
{ "properties" : {
"type" : { "enum" : ["expression","validation"] },
"expression" : { "type" : "string" }
}
}
]
},
...
The expression_field
definition is a combination of base
and one more property named expression
- Is there any way to enforce that an expression field will not have any additional properties other then those specified by both base
and expression_field
?
(in this case the permitted properties are variable,name,visible,type,expression
. I'm reusing the base
schema, each field with it's own specific properties.
Example data might be
{"name":"valid","type":"expression","variable":"x","visible":True,"expression":"n+1"},
{"name":"invalid - additional prop","type":"expression","variable":"x","visible":True,"expression":"n+1","invalid":"prop"},
{"name":"invalid missing properties","type":"expression","variable":"x","visible":True},
An attempt to add additionalProperties
will obviously fail the validation because each definition is validating a specific set of fields.
I'm using python jsonschema
.