定义对象中定义的子模式可以引用另一个子模式吗?
Can a sub-schema defined inside the definitions object refer to another sub-schema?
可能答案太明显了,一文不值,但我找不到任何明确的信息。架构的定义(在 JSON 架构中的 "definitions" 内定义)可以引用另一个定义吗?
我还没有 运行 我的代码,因为我仍在编写架构,我不想把它搞砸。这是我正在尝试做的一个例子:
"definitions": {
"apple": {
"description": "a type of fruit",
"edible": "boolean"
},
"fruit": {
"description": "a type of food",
"edible": "boolean",
"items": {
"$ref": "#definitions/apple"
}
}
}
这很有趣!
从定义中引用另一个定义是有效的。
如果您的引用在 items
而不是 "examples" 下,那么这将是有效的,因为 "items" 的值必须是模式,其中 "examples" 未定义为模式。 ("examples" 必须是一个数组,仅供参考。)
可能答案太明显了,一文不值,但我找不到任何明确的信息。架构的定义(在 JSON 架构中的 "definitions" 内定义)可以引用另一个定义吗?
我还没有 运行 我的代码,因为我仍在编写架构,我不想把它搞砸。这是我正在尝试做的一个例子:
"definitions": {
"apple": {
"description": "a type of fruit",
"edible": "boolean"
},
"fruit": {
"description": "a type of food",
"edible": "boolean",
"items": {
"$ref": "#definitions/apple"
}
}
}
这很有趣!
从定义中引用另一个定义是有效的。
如果您的引用在 items
而不是 "examples" 下,那么这将是有效的,因为 "items" 的值必须是模式,其中 "examples" 未定义为模式。 ("examples" 必须是一个数组,仅供参考。)