【发布时间】:2021-10-18 21:05:33
【问题描述】:
我有一个包含“$ref”标签的 JSON 模式,我正在尝试获取解析了“$ref”标签的 JSON 模式版本。我只想从 JSON Schema 字符串中的定义(标签)解析“$ref”(即不需要外部解析)。
是否有执行 JSON Schema 解析的库? (我目前正在使用 org.everit.json.schema 库,这很棒,但我找不到我需要的方法)。
例如,我原来的架构是:
{
"$id": "https://example.com/arrays.schema.json",
"description": "A representation of a person, company, organization, or place",
"title": "complex-schema",
"type": "object",
"properties": {
"fruits": {
"type": "array",
"items": {
"type": "string"
}
},
"vegetables": {
"type": "array",
"items": { "$ref": "#/$defs/veggie" }
}
},
"$defs": {
"veggie": {
"type": "object",
"required": [ "veggieName", "veggieLike" ],
"properties": {
"veggieName": {
"type": "string",
"description": "The name of the vegetable."
},
"veggieLike": {
"type": "boolean",
"description": "Do I like this vegetable?"
}
}
}
}
}
这将解析为这样的事情(注意“#defs/veggie”解析为其在架构中内联插入的定义):
{
"$id": "https://example.com/arrays.schema.json",
"description": "A representation of a person, company, organization, or place",
"title": "complex-schema",
"type": "object",
"properties": {
"fruits": {
"type": "array",
"items": {
"type": "string"
}
},
"vegetables": {
"type": "array",
"items": {
"type": "object",
"required": [ "veggieName", "veggieLike" ],
"properties": {
"veggieName": {
"type": "string",
"description": "The name of the vegetable."
},
"veggieLike": {
"type": "boolean",
"description": "Do I like this vegetable?"
}
}
}
}
}
}
【问题讨论】:
标签: json jsonschema