I'm new to Json Schema validation. I think the validation should fail, but it passes. Not sure why the If/then is not forcing the required field. I believe I formatted the If/Then correctly.
JSON:
{
"name": "Battery Wear",
"triggerAlert": {
"trigger": "When",
"timeSpan": 50,
"timeSpanMeasure": "Hours"
}
}
SCHEMA:
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"required": [
"name",
"triggerAlert"
],
"properties": {
"name": {
"type": "string"
},
"triggerAlert": {
"type": "object",
"required": ["trigger"],
"properties": {
"trigger": {
"type": "string",
"enum": ["Always","When"]
},
"numberOfEvents": {
"type": "integer"
},
"timeSpan": {
"type": "integer"
},
"timeSpanMeasure": {
"type": "string"
}
},
"if": { "properties": {"trigger": {"enum": ["When"]} } },
"then": {
"required": [
"numberOfEvents",
"timeSpan",
"timeSpanMeasure"
]
}
}
}
}