gpt4 book ai didi

java - Json 模式要求节点处于错误级别

转载 作者:太空宇宙 更新时间:2023-11-04 11:49:05 25 4
gpt4 key购买 nike

我正在尝试通过以下方式创建 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 validator 时,我收到错误,因为我按照“stdItem”的要求指定了“stdAtrributes”节点,而 validator 找不到它。

我尝试在属性内定义所需​​的数组,但架构无效。

如果我将“stdAttributes”放在“stdItem”之外,它就可以工作。

有谁知道我如何定义“stdItem”的这个要求?

最佳答案

架构中的问题是您希望 layoutItem 的值根据 #/definitions/stdItem 处的架构有效。

但是此架构并没有按照您想要的方式定义具有 stdItem 属性的对象(查看您的数据),它定义了具有属性 stdTypestdAttributeschildren 的对象,并要求属性 stdAttributes 存在。换句话说,它是以下数据的架构:

{
"layoutItem": {
"stdType": "CONTAINER",
"stdAttributes": [],
"children": []
}
}

对于您的数据,架构应该是:

 {
...
"definitions": {
...
"stdItem": {
"type": "object",
"required" : ["stdItem"],
"properties": {
"stdItem": {
"type": "object",
"required" : ["stdAttributes"],
"properties": {
"stdType": { ... },
"stdAttributes": { ... },
"children": { ... }
}
}
}
}
},
...
}

关于java - Json 模式要求节点处于错误级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42029582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com