我有一个如下所示的json模式,它具有三个属性height,weight和volume,它们是可选的。但我想在这里进行以下其他检查:
由于这些是可选属性,因此不确定如何实现。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"options": {
"type": "object",
"properties": {
"height": {
"type": "number"
},
"weight": {
"type": "number"
},
"volume": {
"type": "number"
}
}
}
}
}
您正在寻找的是additionalProperties
关键。来自JsonSchema文档
AdditionalProperties关键字用于控制其他内容的处理,即名称未在properties关键字中列出的属性。默认情况下,允许任何其他属性。
因此,此友情变为:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"options": {
"type": "object",
"properties": {
"height": {
"type": "number"
},
"weight": {
"type": "number"
},
"volume": {
"type": "number"
}
},
"additionalProperties": false
}
}
}
以我的理解,此支持自draft 00
,因此应该可以使用draft 4
,但是仅供您了解,此处是第8版。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句