在对象x中,它应该有anyOf a,b,还有anyOf c,d。这是我当前的代码,可以工作,但它似乎不是正确的方法。
{
"type": "object",
"properties": {
"x": {
"type": "object",
"anyOf": [
{
"required": ["a","c"]
},
{
"required": ["a","d"]
},
{
"required": ["b","c"]
},
{
"required": ["b","d"]
}
],
"properties": {
"a": {
"type": "string"
},
"b": {
"type": "string"
},
"c": {
"type": "string"
},
"d": {
"type": "string"
}
}
}
}
}如何以一种更简单的方式做这件事?也就是说,对象x应该有(a或b)和(c或d)。
发布于 2021-09-16 15:30:06
对象x应该有(a或b)和(c或d)
如果这正是您所需要的,那么您可以使用allOf关键字和anyOf来表示这一点。只要把allOf和anyOf看作OR就可以了:
...
"allOf": [
{
"anyOf": [
{ "required": ["a"] },
{ "required": ["b"] }
]
},
{
"anyOf": [
{ "required": ["c"] },
{ "required": ["d"] }
]
}
]https://stackoverflow.com/questions/69205574
复制相似问题