У меня есть следующая схема JSON:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "myJsonSchema",
"type": "object",
"additionalProperties": false,
"properties": {
"flag": {
"type": "boolean"
},
"myArray": {
"type": "array",
"items": {
"$ref": "#/definitions/ArrayItem"
}
}
},
"definitions": {
"ArrayItem": {
"type": "object",
"properties": {
"itemAttribute1": {
"type": "string",
"description": ""
},
"itemAttribute2": {
"type": "string",
"description": ""
}
}
}
},
"allOf": [
{
"if": {
"flag": {
"const": true
}
},
"then": {
"myArray": {
"items": {
"required": "itemAttribute1"
}
}
}
}
]
}
Я хочу проверить, что, когда флаг установлен в true, тогда поле "itemAttribute" является обязательным. Как мне этого добиться?
Примеры:
Этот JSON должен быть действительным:
{
"flag" : true,
"myArray" : [
{
"itemAttribute1" : "c",
"itemAttribute2" : "d"
}
]
}
Хотя этот json не должен быть действительным (поскольку flag = true, itemAttribute1 становится обязательным):
{
"flag" : true,
"myArray" : [
{
"itemAttribute2" : "d"
}
]
}