是否可以在 JSON-Schema(草案 0.7)中将定义作为子定义
Is it possible to have Definitions as sub-definitions in JSON-Schema (Draft 0.7)
好的所以使用 JSON 很长一段时间了 JSON-Schema 的新手,但我正在尝试解决是否可以嵌套定义?
我的意思是: 我希望能够使用 "$ref":"#definitions/link/post"
& "$ref":"#definitions/link/default"
post 定义在 [=36= 下].
{
"$schema": "http://json-schema.org/schema#",
"id":"https://api.thisisbeacon.com/schemas/",
"definitions":{
"link":{
"default":{
"$ref":"link/single.schema.json"
},
"post":{
"$ref":"link/post/single.schema.json"
}
},
},
"$ref":"#definitions/link/post"
}
我正在使用一个有效的测试 json
{
"$schema":"https://api.thisisbeacon.com/schemas/link/post/single.schema.json",
"url":"http://www.google.com",
"post":1,
"channnel":"testing"
}
我正在 https://www.jsonschemavalidator.net/
上测试架构
现在 "$ref":"#definitions/link/default"
架构的底部纯粹用于测试,在真实系统中它不会有任何实际的格式规则,只有定义,但我的目标是拥有它所以所有客户端开发人员都可以使用
进行测试
{
"id":"https://api.thisisbeacon.com/schemas/",
"$ref":"schema.json#/definitions/{the_definition_to_test_with}"
}
在我的测试示例中,我会 {the_definition_to_test_with} = link/post
因此,在与 JSON-Schema 团队合作后,事实证明我的设置对我的节点是正确的,我的 "$ref":"#definitions/link/post"
测试用例是导致问题的原因,它覆盖了原来的定义在同一文件中创建。
"allOf":{"$ref":"#definitions/link/definitions/post/definitions/single"}
好的所以使用 JSON 很长一段时间了 JSON-Schema 的新手,但我正在尝试解决是否可以嵌套定义?
我的意思是: 我希望能够使用 "$ref":"#definitions/link/post"
& "$ref":"#definitions/link/default"
post 定义在 [=36= 下].
{
"$schema": "http://json-schema.org/schema#",
"id":"https://api.thisisbeacon.com/schemas/",
"definitions":{
"link":{
"default":{
"$ref":"link/single.schema.json"
},
"post":{
"$ref":"link/post/single.schema.json"
}
},
},
"$ref":"#definitions/link/post"
}
我正在使用一个有效的测试 json
{
"$schema":"https://api.thisisbeacon.com/schemas/link/post/single.schema.json",
"url":"http://www.google.com",
"post":1,
"channnel":"testing"
}
我正在 https://www.jsonschemavalidator.net/
上测试架构现在 "$ref":"#definitions/link/default"
架构的底部纯粹用于测试,在真实系统中它不会有任何实际的格式规则,只有定义,但我的目标是拥有它所以所有客户端开发人员都可以使用
{
"id":"https://api.thisisbeacon.com/schemas/",
"$ref":"schema.json#/definitions/{the_definition_to_test_with}"
}
在我的测试示例中,我会 {the_definition_to_test_with} = link/post
因此,在与 JSON-Schema 团队合作后,事实证明我的设置对我的节点是正确的,我的 "$ref":"#definitions/link/post"
测试用例是导致问题的原因,它覆盖了原来的定义在同一文件中创建。
"allOf":{"$ref":"#definitions/link/definitions/post/definitions/single"}