JSON 单独对象中属性之间的架构依赖关系

JSON Schema Dependency Between Properties in Separate Objects

正在为以下文档创建架构:

{
    "name": "billy",
    "foo": {
        "this": "something"
    },
    "bar": {
        "that": "something"
    }
}

如果存在 $.foo.this,我希望架构需要 $.bar.that

dependencies 只适用于当前对象,所以必须用 if/then 来完成。您需要使用properties设置每个级别required

{
  "if": {
    "properties": {
      "foo": { "required": ["this"] }
    },
    "required": ["foo"]
  },
  "then": {
    "properties": {
      "bar": { "required": ["this"] }
    },
    "required": ["bar"]
  }
}