如何强制“object”属性只允许列出的属性成为它的一部分,而不允许其他属性成为它的一部分,尤其是空键“"?
{
"type": "object",
"properties": {
"object": {
"type": "object",
"properties": {
"property1": {
"type": "string"
},
"property2": {
"type": "string"
},
"property3": {
"type": "string"
}
},
"uniqueItems": true
}
}
}
2条答案
按热度按时间5jdjgkvh1#
我相信,你要找的是
"additionalProperties": false
。下面是添加了
additionalProperties
的模式。请在此处尝试:https://www.jsonschemavalidator.net/s/RDGrQvL6请注意,我必须从模式中删除额外的
"object"
Package 器才能使其正常工作。xwbd5t1u2#
丹尼尔的答案是正确的,
"additionalProperties": false
也是我需要的,但下面的代码是我实际上想用嵌套对象实现的。