Verified Commit c307438b authored by Dan Jones's avatar Dan Jones
Browse files

refactor: make imported schemas available to tests

- revert changes to emergency schema
- remove Feature and FeatureCollection
parent dc538669
......@@ -13,7 +13,6 @@
"planning_config_ID": 1,
"exclusion_zones": [
{
"geometry": {
"type": "Polygon",
"coordinates": [
[
......@@ -40,11 +39,9 @@
]
]
}
}
],
"region_of_interest": [
{
"geometry": {
"type": "Polygon",
"coordinates": [
[
......@@ -71,7 +68,6 @@
]
]
}
}
],
"squads": [
{
......
......@@ -34,7 +34,8 @@ emergency_schema = {
},
},
"required": [
"target_waypoint",
"target_waypoint_latitude",
"target_waypoint_longitude",
],
}
......
......@@ -30,7 +30,9 @@ FLASK_PORT = os.getenv("FLASK_PORT", 5000)
# Switch on debug mode if env var is truthy
FLASK_DEBUG = os.getenv("FLASK_DEBUG", "False").lower() in ("true", "1", "t")
swagger_config = {
def get_swagger_config():
swagger_config = {
"openapi": "3.0.2",
"swagger_ui": True,
"specs_route": "/",
......@@ -111,7 +113,9 @@ swagger_config = {
"alert": alert_schema,
}
},
}
}
import_remote_refs(swagger_config)
return swagger_config
def resolve_ref(ref):
......@@ -172,6 +176,8 @@ def inject_schema(schema, remote_ref):
local_name = rename_ref(remote_ref)
local_ref = f"#/components/schemas/{local_name}"
ref_schema = resolve_ref(remote_ref)
del ref_schema["$id"]
del ref_schema["$schema"]
if ref_schema is not None:
nested_replace(schema, "$ref", remote_ref, local_ref)
schema["components"]["schemas"][local_name] = ref_schema
......@@ -180,16 +186,19 @@ def inject_schema(schema, remote_ref):
return False
def import_remote_refs():
def import_remote_refs(swagger_config):
"""
inject the following remote refs into the schema
and replace the remote refs with local refs
returns True if all schemas resolved and injected
"""
# For some reason importing Feature or FeatureCollection
# makes the schema fail to validate
ref_imports = [
"https://geojson.org/schema/Feature.json",
"https://geojson.org/schema/FeatureCollection.json",
# "https://geojson.org/schema/Feature.json",
# "https://geojson.org/schema/FeatureCollection.json",
"https://geojson.org/schema/LineString.json",
"https://geojson.org/schema/MultiLineString.json",
"https://geojson.org/schema/MultiPoint.json",
......@@ -312,7 +321,7 @@ def get_options():
if __name__ == "__main__":
import_remote_refs()
swagger_config = get_swagger_config()
# Parse script args
config = get_options()
......
......@@ -111,1045 +111,7 @@
],
"type": "object"
},
"geojson.org.schema.Feature.json": {
"$id": "https://geojson.org/schema/Feature.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"geometry": {
"oneOf": [
{
"type": "null"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"type": {
"enum": [
"Point"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON Point",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 2,
"type": "array"
},
"type": {
"enum": [
"LineString"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON LineString",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 4,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"Polygon"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON Polygon",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiPoint"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiPoint",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 2,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiLineString"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiLineString",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 4,
"type": "array"
},
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiPolygon"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiPolygon",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"geometries": {
"items": {
"oneOf": [
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"type": {
"enum": [
"Point"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON Point",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 2,
"type": "array"
},
"type": {
"enum": [
"LineString"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON LineString",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 4,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"Polygon"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON Polygon",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiPoint"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiPoint",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 2,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiLineString"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiLineString",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 4,
"type": "array"
},
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiPolygon"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiPolygon",
"type": "object"
}
]
},
"type": "array"
},
"type": {
"enum": [
"GeometryCollection"
],
"type": "string"
}
},
"required": [
"type",
"geometries"
],
"title": "GeoJSON GeometryCollection",
"type": "object"
}
]
},
"id": {
"oneOf": [
{
"type": "number"
},
{
"type": "string"
}
]
},
"properties": {
"oneOf": [
{
"type": "null"
},
{
"type": "object"
}
]
},
"type": {
"enum": [
"Feature"
],
"type": "string"
}
},
"required": [
"type",
"properties",
"geometry"
],
"title": "GeoJSON Feature",
"type": "object"
},
"geojson.org.schema.FeatureCollection.json": {
"$id": "https://geojson.org/schema/FeatureCollection.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"features": {
"items": {
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"geometry": {
"oneOf": [
{
"type": "null"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"type": {
"enum": [
"Point"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON Point",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 2,
"type": "array"
},
"type": {
"enum": [
"LineString"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON LineString",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 4,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"Polygon"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON Polygon",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiPoint"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiPoint",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 2,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiLineString"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiLineString",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 4,
"type": "array"
},
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiPolygon"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiPolygon",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"geometries": {
"items": {
"oneOf": [
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"type": {
"enum": [
"Point"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON Point",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 2,
"type": "array"
},
"type": {
"enum": [
"LineString"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON LineString",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 4,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"Polygon"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON Polygon",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiPoint"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiPoint",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 2,
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiLineString"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiLineString",
"type": "object"
},
{
"properties": {
"bbox": {
"items": {
"type": "number"
},
"minItems": 4,
"type": "array"
},
"coordinates": {
"items": {
"items": {
"items": {
"items": {
"type": "number"
},
"minItems": 2,
"type": "array"
},
"minItems": 4,
"type": "array"
},
"type": "array"
},
"type": "array"
},
"type": {
"enum": [
"MultiPolygon"
],
"type": "string"
}
},
"required": [
"type",
"coordinates"
],
"title": "GeoJSON MultiPolygon",
"type": "object"
}
]
},
"type": "array"
},
"type": {
"enum": [
"GeometryCollection"
],
"type": "string"
}
},
"required": [
"type",
"geometries"
],
"title": "GeoJSON GeometryCollection",
"type": "object"
}
]
},
"id": {
"oneOf": [
{
"type": "number"
},
{
"type": "string"
}
]
},
"properties": {
"oneOf": [
{
"type": "null"
},
{
"type": "object"
}
]
},
"type": {
"enum": [
"Feature"
],
"type": "string"
}
},
"required": [
"type",
"properties",
"geometry"
],
"title": "GeoJSON Feature",
"type": "object"
},
"type": "array"
},
"type": {
"enum": [
"FeatureCollection"
],
"type": "string"
}
},
"required": [
"type",
"features"
],
"title": "GeoJSON FeatureCollection",
"type": "object"
},
"geojson.org.schema.LineString.json": {
"$id": "https://geojson.org/schema/LineString.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"bbox": {
"items": {
......@@ -1184,8 +146,6 @@
"type": "object"
},
"geojson.org.schema.MultiLineString.json": {
"$id": "https://geojson.org/schema/MultiLineString.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"bbox": {
"items": {
......@@ -1223,8 +183,6 @@
"type": "object"
},
"geojson.org.schema.MultiPoint.json": {
"$id": "https://geojson.org/schema/MultiPoint.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"bbox": {
"items": {
......@@ -1258,8 +216,6 @@
"type": "object"
},
"geojson.org.schema.MultiPolygon.json": {
"$id": "https://geojson.org/schema/MultiPolygon.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"bbox": {
"items": {
......@@ -1300,8 +256,6 @@
"type": "object"
},
"geojson.org.schema.Point.json": {
"$id": "https://geojson.org/schema/Point.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"bbox": {
"items": {
......@@ -1332,8 +286,6 @@
"type": "object"
},
"geojson.org.schema.Polygon.json": {
"$id": "https://geojson.org/schema/Polygon.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"bbox": {
"items": {
......@@ -1814,7 +766,8 @@
}
},
"required": [
"target_waypoint"
"target_waypoint_latitude",
"target_waypoint_longitude"
],
"type": "object"
},
......
......@@ -5,7 +5,7 @@ from jsonschema.validators import RefResolver
import unittest
import json
import os
from generate_schema_config import write_schema, swagger_config
from generate_schema_config import write_schema, get_swagger_config
MOCK_DATA_DIR = "examples/"
......@@ -24,6 +24,7 @@ class SchemaTestCase(unittest.TestCase):
def setUpClass(cls):
test_schema_path = "tests/test_swagger.json"
os.environ["SCHEMA_PATH"] = test_schema_path
swagger_config = get_swagger_config()
write_schema(swagger_config, test_schema_path)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment