【发布时间】:2021-03-05 08:39:07
【问题描述】:
我创建了以下 json 架构。
{
"type": "object",
"properties": {
"hoge": {
"type": "object",
"properties": {
"code": {
"type": "string"
}
},
"additionalProperties": false
},
"foo": {
"type": "object",
"properties": {
"value": {
"type": "number"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
当 type 为 object 时,我想设置 Additionalproperties = false。 但这是非常冗余的。
我定义了以下定义以避免重复的附加属性,但它没有按预期工作。
{
"definitions": {
"baseObject": {
"type": "object",
"additionalProperties": false
}
},
"allOf": [{ "$ref": "#/definitions/baseObject"}],
"properties": {
"hoge": {
"allOf": [{ "$ref": "#/definitions/baseObject"}],
"properties": {
"code": {
"type": "string"
}
}
},
"foo": {
"allOf": [{ "$ref": "#/definitions/baseObject"}],
"properties": {
"value": {
"type": "number"
}
}
}
}
}
有没有办法应用附加属性:false 来键入对象??
【问题讨论】:
-
您正在使用 JavaScript oder Jquery 或在女巫上下文中您需要将此属性添加到所有对象?
标签: jsonschema