I would like to apply an additional "required" property in an array sub schema based on the presence of a property in the root schema. I have my schema set like this:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required":[
"isParentDependency",
"subArray"
],
"properties": {
"isParentDependency": {
"$id": "#/properties/isParentDependency",
"type": "boolean"
},
"subArray": {
"$id": "#/properties/subArray",
"type": "array",
"items": {
"$id": "#/properties/subArrayItem",
"required": ["alwaysRequiredProp"],
"dependencies": {
"isParentDependency":{
"required":["requiredPropIfIsParentDependency"]
}
},
"properties": {
"alwaysRequiredProp": {
"$id": "#/properties/subArray/items/properties/alwaysRequiredProp",
"type": "boolean"
},
"requiredPropIfIsParentDependency": {
"$id": "#/properties/subArray/items/properties/requiredPropIfIsParentDependency",
"type": "boolean"
}
}
}
}
}
}
Passing Cases
{
"isParentDependency": false,
"subArray": [{
"alwaysRequiredProp": true
}]
}
"isParentDependency": true,
"subArray": [{
"alwaysRequiredProp": true,
"requiredPropIfIsParentDependency":true
}]
}
Failing Cases
{
"isParentDependency": true,
"subArray": [{
"alwaysRequiredProp": true
}]
}
Clearly this is not going to work but I have been unable to figure out how to make a pointer to the root schema (or apply an if/else type solution with a $ref)
Any guidance greatly appreciated!