我有一个模式,它有一个属性,如果枚举与某个值匹配,就需要这个属性。这可以很好地工作。
"oneOf": [
{
"not" : {
"properties": {
"other-val": { "enum" : ["ABC"]}
}
}
},
{ "required": ["ABC-detail"] }
],
但是,基于other-value
枚举是否为"DEF“,我尝试添加第二个字段DEF-detail
。我不确定如何链接这些依赖项。我试着在一个allOf
中添加多个oneOf
,但是我不能给它添加多个相同的键。
发布于 2021-05-04 23:56:40
oneOf
中的一组条件是有效的。例如,我认为这并不排除DEF
不能拥有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"]}}}
}
],
发布于 2021-05-05 08:19:47
这种模式被称为“隐含”。通过将它们与allOf
相结合,您可以很容易地声明多个隐含。
{
"allOf": [
{
"anyOf": [
{
"not": {
"properties": {
"other-val": { "const": "ABC" },
},
"required": ["other-val"]
}
},
{ "required": ["ABC-detail"] }
]
},
... another implication ...,
... another implication ...
]
}
如果您使用的是draft-07或更高版本,那么您还可以使用if
/then
,它只是隐含的一点语法糖。
{
"if": {
"properties": {
"other-val": { "const": "ABC" }
},
"required": ["other-val"]
},
"then": { "required": ["ABC-detail"]
}
可以使用allOf
以与隐含相同的方式组合此模式。
https://stackoverflow.com/questions/67387226
复制相似问题