我正在尝试为带有子菜单的菜单创建正确的 JSON 架构。
所以我应该从 item 定义一个数组,其中应包含三个项目。
1 显示名称,2 URL 和子项(应该是具有相同结构的对象数组)
此时我得到了这个:
{
"type": "array",
"additionalProperties": false, // have no idea what is this for :)
"items": {
"type": "object",
"additionalProperties": false, // have no idea what is this for :)
"description": "MenuLink",
"id": "menuLink",
"properties": {
"display_name": {
"type": "string",
"title": "Link display name",
"minLength": 2
},
"url": {
"type": "string",
"title": "URL address",
"minLength": 2
},
"children": {
"type": "array",
"title": "Childrens",
"additionalItems": false, // have no idea what is this for :)
"items": {
"$ref": "menuLink"
}
}
},
"required": [
"display_name",
"url"
]
}
}
问题是它只对第一级菜单有效
任何帮助将不胜感激
数组中的additionalProperties 不执行任何操作,它只是被忽略。对于对象,它不允许“属性”中未定义的任何其他属性
该模式可能有效也可能无效,具体取决于验证器。参考解析是最棘手的问题,很少有验证器能够正确完成。看看这个:https://github.com/ebdrup/json-schema-benchmark
更传统的方法来创建你想要的东西:
{
"definitions": {
"menuLink": {
"type": "object",
"additionalProperties": false,
"properties": {
"display_name": {
"type": "string",
"title": "Link display name",
"minLength": 2
},
"url": {
"type": "string",
"title": "URL address",
"minLength": 2
},
"children": {
"type": "array",
"title": "Childrens",
"items": { "$ref": "#/definitions/menuLink" }
}
},
"required": [ "display_name", "url" ]
}
},
"type": "array",
"items": { "$ref": "#/definitions/menuLink" }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)