JSON 单独对象中属性之间的架构依赖关系
JSON Schema Dependency Between Properties in Separate Objects
正在为以下文档创建架构:
{
"name": "billy",
"foo": {
"this": "something"
},
"bar": {
"that": "something"
}
}
如果存在 $.foo.this
,我希望架构需要 $.bar.that
。
- 尝试使用指向它的 JSON 指针依赖于它。
- 尝试了 if/then 块,但我不知道如何在块的 if 部分说“
this
存在”。
dependencies
只适用于当前对象,所以必须用 if
/then
来完成。您需要使用properties
设置每个级别required
。
{
"if": {
"properties": {
"foo": { "required": ["this"] }
},
"required": ["foo"]
},
"then": {
"properties": {
"bar": { "required": ["this"] }
},
"required": ["bar"]
}
}
正在为以下文档创建架构:
{
"name": "billy",
"foo": {
"this": "something"
},
"bar": {
"that": "something"
}
}
如果存在 $.foo.this
,我希望架构需要 $.bar.that
。
- 尝试使用指向它的 JSON 指针依赖于它。
- 尝试了 if/then 块,但我不知道如何在块的 if 部分说“
this
存在”。
dependencies
只适用于当前对象,所以必须用 if
/then
来完成。您需要使用properties
设置每个级别required
。
{
"if": {
"properties": {
"foo": { "required": ["this"] }
},
"required": ["foo"]
},
"then": {
"properties": {
"bar": { "required": ["this"] }
},
"required": ["bar"]
}
}