我正在编写类似于这样的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缺少require属性、stdType、和stdAttributes。正如您可以看到的那样,属性是存在的,它们并不缺少。
我试图更改属性的顺序,但仍然不起作用。我一直收到以下错误:
-开始消息-错误:对象缺少必需的属性("stdAttributes","stdType")级别:“错误”架构:{"loadingURI":"#",“指针”:“/loadingURI/stdItem”}实例:{“指针”:“/stdItem/stdType/0”}域:“验证”关键字:“必需”:"stdAttributes","stdType“缺失:"stdAttributes","stdType“--结束消息
有人能指出我做错了什么吗?
发布于 2017-03-21 19:40:33
当您声明“子”属性时,您说它是"stdItem“,因此它希望在那里具有stdAttributes和stdType属性。相反,json中有一个" stdItem“属性,它是stdItem类型的。因此,您在模式中缺少了该属性(stdItem)的声明。
此架构将验证您的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": {
"type": "object",
"properties": {
"stdItem": { "$ref": "#/definitions/stdItem" }
}
}
}
}
}
},
"properties":{
"stdItem": { "$ref": "#/definitions/stdItem" }
}
}注意,我正在向具有"stdItem“属性的”子“项规范中添加一个对象。(我没有按要求声明,但您可能需要添加)
https://stackoverflow.com/questions/42934529
复制相似问题