【发布时间】:2017-02-03 17:15:40
【问题描述】:
我正在尝试通过以下方式创建 json 架构:
{
"$schema": "http://json-schema.org/schema#",
"title": "Layout",
"description": "The layout created by the user",
"type": "object",
"definitions": {
"stdAttribute": {
"type": "object",
"properties": {
"attributeValue": {
"type": "object"
},
"attributeName": {
"type": "string"
}
}
},
"stdItem": {
"type": "object",
"required" : ["stdAttributes"],
"properties": {
"stdType": {
"enum": [
"CONTAINER",
"TEXT",
"TEXTAREA",
"BUTTON",
"LABEL",
"IMAGE",
"MARCIMAGE",
"DATA",
"SELECT",
"TABLE"
]
},
"stdAttributes": {
"type": "array",
"items": {
"$ref": "#/definitions/stdAttribute"
}
},
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/stdItem"
}
}
}
}
},
"properties": {
"layoutItem": {
"$ref": "#/definitions/stdItem"
}
}
}
我正在针对它验证以下 json:
{
"layoutItem": {
"stdItem": {
"stdType": "CONTAINER",
"stdAttributes": [],
"children": []
}
}
}
问题是,当我运行 java 验证器时,我收到一个错误,因为我按照“stdItem”和验证器的要求指定了“stdAtrributes”节点找不到。
我试图在属性中定义所需的数组,但架构无效。
如果我将“stdAttributes”放在“stdItem”之外,它会起作用。
有谁知道我如何为“stdItem”定义这个要求?
【问题讨论】:
标签: java json jsonschema