-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
If a schema contains conditional values, no valid json will be produced from it.
I'm on Windows 10, jsonschema_default 1.5.0 installed via conda.
import jschon
import jsonschema_default
json_schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"mode": {
"type": "string",
"enum": ["S", "A"],
"default": "S"
}
},
"if": {
"properties": {
"mode": {
"const": "S"
}
}
},
"then": {
"properties": {
"x": {
"type": "number",
"default": 0.0
}
},
"required": ["x"]
},
"else": {
"properties": {
"y": {
"type": "number",
"default": 0.0
}
},
"required": ["y"]
}
}
defaults = jsonschema_default.create_from(json_schema)
jschon.create_catalog("2020-12")
jschon_schema = jschon.JSONSchema(json_schema)
validation_result = jschon_schema.evaluate(jschon.JSON(defaults))
print(f"Is valid: {validation_result.valid}")
In this example, the defaults dict contains a mode property, but no x property, which results in a negative validation result.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels