1

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.

haki
  • 9,389
  • 15
  • 62
  • 110
  • What have you tried with "additionalProperties"? Related question: http://stackoverflow.com/questions/22689900/json-schema-allof-with-additionalproperties – jruizaranguren Jul 28 '14 at 07:58
  • I cant use `addtionalProperties` in this case because each field type has it's own required set pf properties. this is why a resorted to a "inheritance" approach using `$ref`. – haki Jul 28 '14 at 08:30
  • But you could use additionalProperties in each needed child schema. You can decide for each field type if additionalProperties are allowed or not. Or I'm missing something. – jruizaranguren Jul 28 '14 at 09:35

0 Answers0