8

我们可以强制执行对象类型的空属性,如下所示:

{
   "description": "voice mail record",
   "type": "object",
   "additionalProperties": false,
   "properties": {}
}

如此所述。

现在我想验证哪个属性

  1. 是对象类型,
  2. 没有任何预定义的属性
  3. 可以具有字符串或数字类型的属性
  4. 不应为空

强制非空(第 4 点)是我无法猜测的。这与上面示例中的强制清空有些相反。我当前的 json 模式摘录如下所示:

"attribute": 
{
    "type": "object",
    "additionalProperties": { "type": ["string","number","integer"] }
}

但以上并不强制非空。我怎样才能做到这一点?

4

1 回答 1

15

听起来minProperties就是你想要的。

{
    "type": "object",
    "additionalProperties": {"type": ["string", "number", "integer"]},
    "minProperties": 1
}

还有maxProperties, 可以用作您链接到的相反问题的替代解决方案。

于 2016-02-26T13:04:27.757 回答