我想知道你是否可以为一个房产制定多条规则。所有的例子似乎都暗示你不能。
所以我希望有类似的东西:
"properties": {
"track": {
"type": "string",
"pattern": "(exclusive)"
},
"track": {
"type": "string",
"pattern": "(featuring)"
}
}
我知道在这个例子中显而易见的事情就是让模式有"(exclusive)|(featuring)"
,但我想我想知道哪个规则失败了。同样,我可能想要更加复杂的模式,这可能不会被|
解决。
您可以将模式与allOf
,anyOf
和oneOf
关键字组合使用。这些关键字中的每一个都采用一系列模式,并按照它的说法执行。如果所有模式都有效,则allOf
有效。如果任何模式有效,anyOf
有效。如果其中一个模式有效,则oneOf
有效。
这是解决问题的方法之一。
{
"type": "object",
"properties": {
"track": {
"anyOf": [
{
"type": "string",
"pattern": "(exclusive)"
},
{
"type": "string",
"pattern": "(featuring)"
}
]
}
}
}