如何从另一个模式引用json模式定义
我有一个json模式,将几何体表示为点或多点。每个都在“定义”中的模式中定义: 现在我想创建另一个模式,它使用点定义。目前,我在属性“startPosition”和“endPosition”中复制粘贴了点和位置的定义,效果良好。但是有没有办法从我的geometry.json模式中引用点的定义呢 注意:我只想在这里使用点,而不是多点-geometry.json ref将同时允许这两种情况如何从另一个模式引用json模式定义,json,jsonschema,schema-design,Json,Jsonschema,Schema Design,我有一个json模式,将几何体表示为点或多点。每个都在“定义”中的模式中定义: 现在我想创建另一个模式,它使用点定义。目前,我在属性“startPosition”和“endPosition”中复制粘贴了点和位置的定义,效果良好。但是有没有办法从我的geometry.json模式中引用点的定义呢 注意:我只想在这里使用点,而不是多点-geometry.json ref将同时允许这两种情况 { "$schema": "http://json-schema.org/draft-04/schem
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://schema.my-site.org/myitem.json#",
"type": "object",
"additionalProperties": false,
"required": [
"myproperty"
],
"properties": {
"myproperty": {
"type": "array",
"minItems": 0,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
},
"startPosition": {
"geometry": {
"required": [
"type",
"coordinates"
],
"title": "Point",
"type": "object",
"properties": {
"type": {
"enum": [
"Point"
]
},
"coordinates": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"additionalItems": false,
"items": [
{
"type": "number"
},
{
"type": "number"
}
]
}
}
}
},
"endPosition": {
"geometry": {
"required": [
"type",
"coordinates"
],
"title": "Point",
"type": "object",
"properties": {
"type": {
"enum": [
"Point"
]
},
"coordinates": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"additionalItems": false,
"items": [
{
"type": "number"
},
{
"type": "number"
}
]
}
}
}
}
}
}
}
}
}
我自己还没有测试过,但根据,您可以利用: 在geometry.json文件中:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://schema.my-site.org/geometry.json",
"type": "object",
"definitions": {
"Point": { ...},
"MultiPoint": {...}
}
}
在文件myitem.json中:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://schema.my-site.org/myitem.json#",
"type": "object",
"properties": {
"point": {
"$ref": "http://schema.my-site.org/geometry.json#definitions/Point"
}
}
}
根据,人们不应该相信验证器正确地处理任意URI。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://schema.my-site.org/myitem.json#",
"type": "object",
"properties": {
"point": {
"$ref": "http://schema.my-site.org/geometry.json#definitions/Point"
}
}
}