json - 单独对象中的属性之间的 JSON 模式依赖关系
问题描述
为以下文档创建架构:
{
"name": "billy",
"foo": {
"this": "something"
},
"bar": {
"that": "something"
}
}
$.bar.that
如果$.foo.this
存在,我希望架构需要。
- 尝试使用指向它的 JSON 指针来依赖它。
- 尝试了 if/then 块,但我不知道如何
this
在块的 if 部分中说“存在”。
解决方案
dependencies
仅适用于当前对象,因此必须使用if
/来完成then
。您需要在每个级别使用properties
来设置。required
{
"if": {
"properties": {
"foo": { "required": ["this"] }
},
"required": ["foo"]
},
"then": {
"properties": {
"bar": { "required": ["this"] }
},
"required": ["bar"]
}
}
推荐阅读
- unity3d - 如何构建可跨场景重用的统一 UI 组件
- python-3.x - 使用 selenium/python 和 openpyxl 将值从 excel 发送到网页上的输入字段
- assembly - 汇编在模式 x 下读取平面是否需要与写入不同的 VGA 端口输出?
- python - 字段集中的“wide”和“extrapretty”类有什么用?
- apache-kafka - 启用 auto.create.topics 时 Kafka 删除主题
- c++ - Freetype 正确尺寸渲染
- elasticsearch - 弹性搜索 - elasticsearch.yml 中未配置节点属性 如果没有节点属性,您将无法控制分片分配
- drupal - Drupal Group 模块,以编程方式将用户添加到具有特定角色的组
- vue.js - 在 vue Bootstrap 数据表中添加事件
- php - 将相同的数组值相加到单个数组中