【发布时间】:2016-02-07 06:48:39
【问题描述】:
它是一个有效的 json 架构吗:
object:
$ref: '#/definitions/object'
你会推荐使用这种格式吗?
【问题讨论】:
-
这个运气好吗?
标签: jsonschema
它是一个有效的 json 架构吗:
object:
$ref: '#/definitions/object'
你会推荐使用这种格式吗?
【问题讨论】:
标签: jsonschema
自引用是允许且有用的。但是,您的示例看起来只是一个引用无限循环。下面是一个 JSON Schema 示例,它使用递归引用来定义无限深度的树结构。
{
"type": "object",
"properties": {
"name": { "type": "string" },
"tree": { "$ref": "#/definitions/tree" }
},
"definitions": {
"tree": {
"type": "object",
"properties": {
"value": { "type": "string" },
"branches": {
"type": "array",
"items": { "$ref": "#/definitions/tree" },
"minItems": 1
}
},
"required": ["value"]
}
}
}
【讨论】: