-
-
Notifications
You must be signed in to change notification settings - Fork 601
Description
Hi,
there seems to be a problem with validating against the additionalProperties: false constraint when extending a schema using draft 3.
import json, jsonschema
validator = jsonschema.Draft3Validator(json.loads('''{
"type": "object",
"extends": {
"properties": {
"id": {
"type": "string"
}
}
},
"properties": {},
"additionalProperties": false
}'''))
instance = {'id': 'should be allowed.'}
print([e.message for e in validator.iter_errors(instance)])
=>
["Additional properties are not allowed ('id' was unexpected)"]
I know about the problematic nature of the wording in the draft 3 specs (the behavior of extends can be seen as validating an instance against all constraints in the extending schema as well as the extended schema(s)) and that draft 4 should be preferred, but is there any chance this will be fixed?
In my real world application extends is basically used to emulate mutli level inheritance using $refs, so it's quite a bit more complex than my example here.
In case this won't/can't be fixed in the library, I came up with 3 ways to fix this on the application side so far:
- Rewrite all schemas for draft 4.
- Get rid of all the
extendsand inline everything. - Add empty property definitions (i.e. declarations) for all inherited properties, so for my example above that would mean adding
"id": {}to the schema's properties.
1 & 2 being the most time consuming, 3 being kind of an ugly hack. Can you think of yet another, more practical solution?
Thanks.