json - json模式中的多个条件必填字段
问题描述
如果枚举匹配某个值,我有一个具有所需属性的架构。这工作正常。
"oneOf": [
{
"not" : {
"properties": {
"other-val": { "enum" : ["ABC"]}
}
}
},
{ "required": ["ABC-detail"] }
],
但是,我正在尝试添加第二个字段,DEF-detail
基于other-value
枚举是否为“DEF”。我不确定如何将这些依赖项链接起来。我尝试将多个oneOf
s 放入其中allOf
,但我无法向其中添加多个相同键。
解决方案
作品中的一组条件oneOf
。但我不认为这排除了 aDEF
的abc-thing
情况,例如,但这在我的情况下是可以的。
"oneOf": [
{
"properties": {"other-val": {"enum": ["ABC"]}},
"required": ["abc-thing"]
},
{
"properties": {"other-val": {"enum": ["DEF"]}},
"required": ["def-thing"]
},
{
"properties": {"other-val": {"enum": ["GHI"]}},
"required": ["ghi-thing"]
},
{
"not": {"properties": {"other-val": {"enum": ["ABC", "DEF", "GHI"]}}}
}
],
推荐阅读
- linux - docker 处理 tar 文件时出错(退出状态 1):设备上没有剩余空间
- keras-2 - 当你在 keras 中合并不同形状的分支时会发生什么?
- python - 为什么我的 if 语句的一部分显示,而另一部分没有?
- html - 如何在硒定位器中定位“::after”元素?
- node.js - Node.js 是否可以禁止客户端访问 /register_success 端点,除非通过 res.redirect()?
- mysql - 选择高于或低于 0.00 的值
- c++ - 警告:不需要函数“F”,也不会发出
- r - 如何排除列中的变量并将列保存为不同的名称?
- c - 尝试水平翻转图像
- java - 每个循环Java的可迭代反向