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,64 +13,60 @@
"planning_config_ID": 1,
"exclusion_zones": [
{
"geometry": {
"type": "Polygon",
"coordinates": [
"type": "Polygon",
"coordinates": [
[
[
[
-4.1777839187560915,
50.34173405662855
],
[
-4.1777839187560915,
50.33820949229701
],
[
-4.143667777943875,
50.33820949229701
],
[
-4.143667777943875,
50.34173405662855
],
[
-4.1777839187560915,
50.34173405662855
]
-4.1777839187560915,
50.34173405662855
],
[
-4.1777839187560915,
50.33820949229701
],
[
-4.143667777943875,
50.33820949229701
],
[
-4.143667777943875,
50.34173405662855
],
[
-4.1777839187560915,
50.34173405662855
]
]
}
]
}
],
"region_of_interest": [
{
"geometry": {
"type": "Polygon",
"coordinates": [
"type": "Polygon",
"coordinates": [
[
[
[
-4.1777839187560915,
50.34173405662855
],
[
-4.1777839187560915,
50.33820949229701
],
[
-4.143667777943875,
50.33820949229701
],
[
-4.143667777943875,
50.34173405662855
],
[
-4.1777839187560915,
50.34173405662855
]
-4.1777839187560915,
50.34173405662855
],
[
-4.1777839187560915,
50.33820949229701
],
[
-4.143667777943875,
50.33820949229701
],
[
-4.143667777943875,
50.34173405662855
],
[
-4.1777839187560915,
50.34173405662855
]
]
}
]
}
],
"squads": [
......
......@@ -34,7 +34,8 @@ emergency_schema = {
},
},
"required": [
"target_waypoint",
"target_waypoint_latitude",
"target_waypoint_longitude",
],
}
......
......@@ -30,88 +30,92 @@ 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 = {
"openapi": "3.0.2",
"swagger_ui": True,
"specs_route": "/",
"info": {
"title": "SoAR Backbone Message Formats",
"version": "1.0",
"description": "SoAR message protocol in schemas",
},
"specs": [
{
"endpoint": "swagger",
"route": "/soar_protocol.json",
}
],
"url_prefix": URL_PREFIX,
"paths": {},
"components": {
"schemas": {
"MESSAGE": {
"type": "object",
"description": "Full message definition with"
+ " message-metadata in `header` and different"
+ " message type schemas under `payload`",
"properties": {
"header": {
"$ref": "#/components/schemas/header",
def get_swagger_config():
swagger_config = {
"openapi": "3.0.2",
"swagger_ui": True,
"specs_route": "/",
"info": {
"title": "SoAR Backbone Message Formats",
"version": "1.0",
"description": "SoAR message protocol in schemas",
},
"specs": [
{
"endpoint": "swagger",
"route": "/soar_protocol.json",
}
],
"url_prefix": URL_PREFIX,
"paths": {},
"components": {
"schemas": {
"MESSAGE": {
"type": "object",
"description": "Full message definition with"
+ " message-metadata in `header` and different"
+ " message type schemas under `payload`",
"properties": {
"header": {
"$ref": "#/components/schemas/header",
},
"payload": {"$ref": "#/components/schemas/payload"},
},
"payload": {"$ref": "#/components/schemas/payload"},
"required": ["header", "payload"],
},
"required": ["header", "payload"],
},
"payload": {
"discriminator": {
"propertyName": "message_type",
"mapping": {
"alert": "#/components/schemas/alert",
"mission_plan": "#/components/schemas/mission_plan",
"mission_plan_encoded": "#/components/schemas/"
+ "mission_plan_encoded",
"observation": "#/components/schemas/observation",
"observation_encoded": "#/components/schemas/"
+ "observation_encoded",
"planning_configuration": "#/components/schemas/"
+ "planning_configuration",
"platform_status": "#/components/schemas/platform_status",
"platform_status_encoded": "#/components/schemas/"
+ "platform_status_encoded",
"acknowledgement": "#/components/schemas/acknowledgement",
"survey": "#/components/schemas/survey",
"survey_encoded": "#/components/schemas/" + "survey_encoded",
"payload": {
"discriminator": {
"propertyName": "message_type",
"mapping": {
"alert": "#/components/schemas/alert",
"mission_plan": "#/components/schemas/mission_plan",
"mission_plan_encoded": "#/components/schemas/"
+ "mission_plan_encoded",
"observation": "#/components/schemas/observation",
"observation_encoded": "#/components/schemas/"
+ "observation_encoded",
"planning_configuration": "#/components/schemas/"
+ "planning_configuration",
"platform_status": "#/components/schemas/platform_status",
"platform_status_encoded": "#/components/schemas/"
+ "platform_status_encoded",
"acknowledgement": "#/components/schemas/acknowledgement",
"survey": "#/components/schemas/survey",
"survey_encoded": "#/components/schemas/" + "survey_encoded",
},
},
"oneOf": [
{"$ref": "#/components/schemas/alert"},
{"$ref": "#/components/schemas/acknowledgement"},
{"$ref": "#/components/schemas/mission_plan"},
{"$ref": "#/components/schemas/mission_plan_encoded"},
{"$ref": "#/components/schemas/observation"},
{"$ref": "#/components/schemas/observation_encoded"},
{"$ref": "#/components/schemas/planning_configuration"},
{"$ref": "#/components/schemas/platform_status"},
{"$ref": "#/components/schemas/platform_status_encoded"},
{"$ref": "#/components/schemas/survey"},
{"$ref": "#/components/schemas/survey_encoded"},
],
},
"oneOf": [
{"$ref": "#/components/schemas/alert"},
{"$ref": "#/components/schemas/acknowledgement"},
{"$ref": "#/components/schemas/mission_plan"},
{"$ref": "#/components/schemas/mission_plan_encoded"},
{"$ref": "#/components/schemas/observation"},
{"$ref": "#/components/schemas/observation_encoded"},
{"$ref": "#/components/schemas/planning_configuration"},
{"$ref": "#/components/schemas/platform_status"},
{"$ref": "#/components/schemas/platform_status_encoded"},
{"$ref": "#/components/schemas/survey"},
{"$ref": "#/components/schemas/survey_encoded"},
],
},
"header": message_header,
"mission_plan": mission_plan_schema,
"mission_plan_encoded": mission_plan_encoded_schema,
"observation": observation_schema,
"observation_encoded": observation_encoded_schema,
"planning_configuration": planning_configuration_schema,
"platform_status": platform_status_schema,
"platform_status_encoded": platform_status_encoded_schema,
"survey": survey_schema,
"survey_encoded": survey_encoded_schema,
"acknowledgement": acknowledgement_schema,
"alert": alert_schema,
}
},
}
"header": message_header,
"mission_plan": mission_plan_schema,
"mission_plan_encoded": mission_plan_encoded_schema,
"observation": observation_schema,
"observation_encoded": observation_encoded_schema,
"planning_configuration": planning_configuration_schema,
"platform_status": platform_status_schema,
"platform_status_encoded": platform_status_encoded_schema,
"survey": survey_schema,
"survey_encoded": survey_encoded_schema,
"acknowledgement": acknowledgement_schema,
"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