使用 6.5 版
我的问题是我有一个请求对象,该对象必须包含一个属性,并且应该包含属性列表中的一个且仅包含一个其他属性,或者没有那些指定的属性。我已经进行了一些挖掘,但无法找到解决此问题的方法。
可能的有效请求:
{ 'query': {...}, 'limit': 1 }
{ 'query': {...}, 'count': true }
{ 'query': {...}, 'max': 'my_string' }
无效的请求是:
{ 'query': {...}, 'limit': 1, 'count': true }
或者
{ 'query': {...}, 'max': 'my_string', limit: 1 }
等等
我想出的最好的 ajv 验证器对象如下:
{
"type": "object",
"required": ["query"],
"maxProperties": 2,
"properties": {
"query": {
"type": "object"
},
"limit": {
"type": "integer"
},
"count": {
"type": "boolean"
},
"max": {
"type": "string"
}
}
}
但我知道这不会随着我们应用程序的增长而扩展。我想知道是否有办法指定对象需要“查询”和“限制”、“计数”、“最大值”的 ONE 或 NONE。