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()
......
This diff is collapsed.
......@@ -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