【发布时间】:2018-11-29 23:03:12
【问题描述】:
我正在尝试创建一个 json 架构,该架构根据对象的类型对其进行验证。它选择正确的定义,但是,它不会验证所选定义中的必需属性。这是我正在尝试的 json 架构:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"literal": {
"type": "object",
"properties": {
"raw": { "type": "string" }
},
"required": ["raw"],
"additionalProperties": false
},
"identifier": {
"type": "object",
"properties": {
"name": { "type": "string" }
},
"required": ["name"],
"additionalProperties": false
}
},
"type": "object",
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"enum": ["Literal"]
},
"content": { "$ref": "#/definitions/literal" }
}
},
{
"type": "object",
"properties": {
"type": {
"enum": ["Identifier"]
},
"content": { "$ref": "#/definitions/identifier" }
}
}
],
"required": ["type"]
};
以下架构是有效的,即使它缺少“原始”属性:
{ "type" : "Literal" }
谢谢
【问题讨论】:
标签: json jsonschema