我想根据其他一些属性的值添加有条件的要求。 仅当“ isInexperienced”时才需要“ companyName”和“ companyAddress” 值是假的。
架构
{
"type": "object",
"properties": {
"previous_employment_section": {
"type": "array",
"items": {
"type": "object",
"properties": {
"companyAddress": {
"type": "string"
},
"companyName": {
"type": "string"
}
},
"if": {
"#/properties/isInexperienced": {
"const": false
}
},
"then": {
"required": [
"companyName",
"companyAddress"
]
}
}
},
"isInexperienced": {
"type": "boolean"
}
}
}
数据
{
"previous_employment_section": [],
"isInexperienced": true
}
答案 0 :(得分:1)
我不完全了解您的原始模式的意图,但是这个模式呢?
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"previous_employment_section": {
"type": "array",
"items": {
"type": "object",
"properties": {
"companyAddress": {
"type": "string"
},
"companyName": {
"type": "string"
}
}
}
},
"isInexperienced": {
"type": "boolean"
}
},
"if": {
"properties": {
"isInexperienced": {
"const": false
}
}
},
"then": {
"properties": {
"previous_employment_section": {
"items": {
"required": [
"companyName",
"companyAddress"
]
},
"minItems": 1
}
}
}
}
答案 1 :(得分:1)
不可能。我们需要更高级别的“如果”,则可以嵌套“属性”。可以使用Leadpony的方法。