将 json 模式限制为来自 GeoJson 的多边形
Restrict json schema to Polygon from GeoJson
我正在构建一个 JSON 架构,其中包含 属性 boundary
。我正在引用工作正常的 GeoJson 模式。现在我想将我的边界限制为 Polygon
类型,这是来自 GeoJson 模式的 enum
。
怎么做?
这是我的架构的相关部分:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"plot": {
"type": "object",
"properties": {
"boundary": {
"description": "The boundary of the plot",
"title": "Plot boundary",
"additionalProperties": false,
"required": [
"type",
"coordinates",
"crs"
],
"TODO": "Restrict to (multi)polygons only.",
"$ref": "http://json.schemastore.org/geojson"
}
}
}
}
}
这是我的验证 json:
{
"plot":
{
"boundary": {
"crs": {
"type": "name",
"properties": {
"name": "EPSG:3857"
}
},
"coordinates": [],
"type": "MultiPolygon"
}
}
}
我好像用错了geojson。
我更改了我的代码,现在它按预期工作,新模式也是 draft-7。
这是我更新的代码:
"boundary": {
"title": "The boundary of the plot",
"anyOf": [
{
"$ref": "http://geojson.org/schema/MultiPolygon.json"
},
{
"$ref": "http://geojson.org/schema/Polygon.json"
}
],
"additionalProperties": false
和
"geoLocation": {
"title": "Front door geolocation",
"$ref": "http://geojson.org/schema/Point.json",
"additionalProperties": false
},
JSON 可能是:
"boundary":
{
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0],
[100.0, 0.0]
]
]
}
和
"geoLocation": {
"coordinates": [125.25, 135.255],
"type": "Point"
}
我正在构建一个 JSON 架构,其中包含 属性 boundary
。我正在引用工作正常的 GeoJson 模式。现在我想将我的边界限制为 Polygon
类型,这是来自 GeoJson 模式的 enum
。
怎么做?
这是我的架构的相关部分:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"plot": {
"type": "object",
"properties": {
"boundary": {
"description": "The boundary of the plot",
"title": "Plot boundary",
"additionalProperties": false,
"required": [
"type",
"coordinates",
"crs"
],
"TODO": "Restrict to (multi)polygons only.",
"$ref": "http://json.schemastore.org/geojson"
}
}
}
}
}
这是我的验证 json:
{
"plot":
{
"boundary": {
"crs": {
"type": "name",
"properties": {
"name": "EPSG:3857"
}
},
"coordinates": [],
"type": "MultiPolygon"
}
}
}
我好像用错了geojson。 我更改了我的代码,现在它按预期工作,新模式也是 draft-7。 这是我更新的代码:
"boundary": {
"title": "The boundary of the plot",
"anyOf": [
{
"$ref": "http://geojson.org/schema/MultiPolygon.json"
},
{
"$ref": "http://geojson.org/schema/Polygon.json"
}
],
"additionalProperties": false
和
"geoLocation": {
"title": "Front door geolocation",
"$ref": "http://geojson.org/schema/Point.json",
"additionalProperties": false
},
JSON 可能是:
"boundary":
{
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0],
[100.0, 0.0]
]
]
}
和
"geoLocation": {
"coordinates": [125.25, 135.255],
"type": "Point"
}