我正在使用json模式的草案4,并且需要提供一些必需的属性,但前提是另一个属性中存在枚举: 因此,仅出于论点考虑,如果我的“实体”数组中存在“ option3”,则需要“ option_overwrite”和“ option_list”。
有效条目可以是:
entities: [option1, option2]
OR
entities: [option1, option3]
option_overwrite: true
option_list: [obj1, obj2]
但是这应该失败:
entities: [option1, option3]
草案4是否有可能,还是需要草案6/7的if,then else语句?
我当前的模式如下所示,大约有50%的时间使用默认属性进行了验证:
{
"title": "Parameters",
"description": "run time parameters",
"type": "object",
"properties": {
"entities": {
"description": "Entities to import",
"type": "array",
"items": {
"type": "string",
"enum": [
"option1",
"option2",
"option3"
]
},
"default": [
"option1",
"option2"
]
},
"option_list": {
"description": "item list",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"option_overwrite": {
"description": "overwrite option",
"type": "boolean"
}
},
"anyOf": [
{
"not": {
"$ref": "#/definitions/contains-option3"
}
},
{
"required": [
"option_overwrite",
"option_list"
]
}
],
"definitions": {
"contains-option3": {
"properties": {
"entities": {
"not": {
"items": {
"not": {
"enum": [
"option3"
]
}
}
}
}
}
}
}
}
谢谢。