【发布时间】:2017-03-21 17:45:07
【问题描述】:
我正在处理这样的 json 架构:
{
"$schema": "http://json-schema.org/schema#",
"title": "Layout",
"description": "The layout created by the user",
"type": "object",
"definitions": {
"stdAttribute": {
"type": "object",
"required": ["attributeName","attributeValue"],
"properties": {
"attributeValue": {
"type": "string"
},
"attributeName": {
"type": "string"
}
}
},
"stdItem": {
"type": "object",
"required" : ["stdType","stdAttributes"],
"properties": {
"stdType": {
"enum": [
"CONTAINER",
"TEXT",
"TEXTAREA",
"BUTTON",
"LABEL",
"IMAGE",
"MARCIMAGE",
"DATA",
"SELECT",
"TABLE"
]
},
"stdAttributes": {
"type": "array",
"items": {
"$ref": "#/definitions/stdAttribute"
},
"minItems": 1
},
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/stdItem"
}
}
}
}
},
"properties":{
"stdItem":{ "$ref": "#/definitions/stdItem" }
}
}
我正在尝试使用上述方案验证以下 json:
{
"stdItem": {
"stdType": "CONTAINER",
"stdAttributes": [
{
"attributeName": "ola",
"attributeValue": "teste"
}
],
"children": [
{
"stdItem": {
"stdType": "TEXT",
"stdAttributes": [
{
"attributeName": "ola",
"attributeValue": "teste"
}
],
"children": []
}
}
]
}
}
我收到一条错误消息,告诉我路径 stdItem/children/0 缺少必需属性 stdType 和 stdAttributes。如您所见,属性在那里,它们并没有丢失。
我尝试更改属性的顺序,但仍然不起作用。我不断收到以下错误:
--- BEGIN MESSAGES --- 错误:对象缺少必需的属性 (["stdAttributes","stdType"]) 级别:“错误” 架构:{"loadingURI":"#","pointer":"/definitions/stdItem"} 实例:{“指针”:“/stdItem/children/0”} 域:“验证” 关键词:“必需” 必需:["stdAttributes","stdType"] 缺少:["stdAttributes","stdType"] --- 结束信息 ---
谁能指出我做错了什么?
【问题讨论】:
标签: json jsonschema json-schema-validator