'jsonschema.exceptions.SchemaError: 'maximum' is a dependency of 'exclusiveMaximum'
I get a metaschema validation error when using python's jsonschema module. Try running this code to replicate:
import json
from jsonschema import validate
myschema = """
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"borderFrac": {
"type": "number",
"exclusiveMinimum": 0.0,
"exclusiveMaximum": 0.5
}
}
}
"""
validate({"borderFrac": 0.4}, schema=json.loads(myschema))
This is the error I get:
jsonschema.exceptions.SchemaError: 'maximum' is a dependency of 'exclusiveMaximum'
Why?
Solution 1:[1]
It's throwing that error because "exclusiveMinimum" and "exclusiveMaximum" changed behaviour in between schema versions "draft-04" and "2020-12":
In JSON Schema Draft 4, exclusiveMinimum and exclusiveMaximum work differently. There they are boolean values, that indicate whether minimum and maximum are exclusive of the value. For example:
- if exclusiveMinimum is false, x ? minimum.
- if exclusiveMinimum is true, x > minimum. This was changed to have better keyword independence.
Fix: Therefore we should update the "$schema" to the latest one:
...
"$schema": "https://json-schema.org/drafts/2020-12/schema",
...
Note that it's actually a substantial number of versions since draft 04, which was released in 2013-01.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |