Commit bc7486ed authored by Trishna Saeharaseelan's avatar Trishna Saeharaseelan
Browse files

refactor: schemas and added abstract message

parent 806f47dc
...@@ -8,5 +8,5 @@ ...@@ -8,5 +8,5 @@
"encoded": false, "encoded": false,
"message_type": "acknowledgement", "message_type": "acknowledgement",
"acknowledged_message_ID": "11111111-7bc8-11ed-a1eb-0242ac999999", "acknowledged_message_ID": "11111111-7bc8-11ed-a1eb-0242ac999999",
"status": "Approved and sent to platform" "status": "c2_received"
} }
\ No newline at end of file
...@@ -6,3 +6,67 @@ __all__ = [ ...@@ -6,3 +6,67 @@ __all__ = [
for x in os.listdir(os.path.dirname(__file__)) for x in os.listdir(os.path.dirname(__file__))
if x.endswith(".py") and x != "__init__.py" if x.endswith(".py") and x != "__init__.py"
] ]
abstract_schema = {
"allOf": [{"$ref": "#/definitions/Metadata"}],
"type": "object",
"properties": {
"payload": {}
}
}
message_metadata = {
"type": "object",
"discriminator": {
"propertyName": "message_type",
},
"properties": {
"message_ID": {
"type": "string",
"description": "An identifier for the type of message received.",
"example": "b427003c-0000-11aa-a1eb-bvcdfghjgfdd",
},
"timestamp": {
"type": "string",
"format": "date-time",
"description": "Timestamp of message",
"example": "2022-11-16T00:00:00Z",
},
"message_type": {
"type": "string",
"description": "Type of message",
"example": "platform_status",
},
"version": {
"type": "number",
"format": "float",
"description": "Version of comms backbone message format protocol",
"example": 2.0,
},
"source": {
"type": "string",
"description": "The sender; Where is this message from",
"example": "autonomy_engine",
},
"destination": {
"type": "string",
"description": "Publisher topic; What is the destination"
+ " of this message",
"example": "ah1",
},
"encoded": {
"type": "boolean",
"description": "Indicate that message raw (encoded) or decoded. "
+ "Options: encoded=True, decoded=False",
"example": False,
},
"delivery_type": {
"type": "string",
"description": "To publish or broadcast this message.",
"enum": ["broadcast", "publish"],
"example": "publish",
"default": "publish",
},
},
"required": ["message_type"],
}
\ No newline at end of file
...@@ -2,12 +2,9 @@ ...@@ -2,12 +2,9 @@
schemas: Acknowledgement status sent by the surface platform to report schemas: Acknowledgement status sent by the surface platform to report
receipt of message. receipt of message.
""" """
# from openapi_schema_validator import validate from formats import abstract_schema
# from jsonschema import validate
acknowledgement_schema = { acknowledgement_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"acknowledged_message_ID": { "acknowledged_message_ID": {
...@@ -29,7 +26,5 @@ acknowledgement_schema = { ...@@ -29,7 +26,5 @@ acknowledgement_schema = {
"required": ["acknowledged_message_ID", "status"], "required": ["acknowledged_message_ID", "status"],
} }
# validate( full_acknowledgement_schema = abstract_schema
# {"acknowledged_message_ID": "string-type-id", "status": "c2_received"}, full_acknowledgement_schema["properties"]["payload"] = acknowledgement_schema
# acknowledgement_schema,
# )
""" # """
schemas: Message Wrapper is used to wrap all message types that contain # schemas: Message Wrapper is used to wrap all message types that contain
details of where the message is coming from, which end client is its # details of where the message is coming from, which end client is its
destination and the type of message. # destination and the type of message.
""" # """
message_wrapper_schema = { # message_wrapper_schema = {
"type": "object", # "type": "object",
"discriminator": { # "discriminator": {
"propertyName": "message_type", # "propertyName": "message_type",
}, # },
"properties": { # "properties": {
"message_ID": { # "message_ID": {
"type": "string", # "type": "string",
"description": "An identifier for the type of message received.", # "description": "An identifier for the type of message received.",
"example": "b427003c-0000-11aa-a1eb-bvcdfghjgfdd", # "example": "b427003c-0000-11aa-a1eb-bvcdfghjgfdd",
}, # },
"timestamp": { # "timestamp": {
"type": "string", # "type": "string",
"format": "date-time", # "format": "date-time",
"description": "Timestamp of message", # "description": "Timestamp of message",
"example": "2022-11-16T00:00:00Z", # "example": "2022-11-16T00:00:00Z",
}, # },
"message_type": { # "message_type": {
"type": "string", # "type": "string",
"description": "Type of message", # "description": "Type of message",
"example": "platform_status", # "example": "platform_status",
}, # },
"version": { # "version": {
"type": "number", # "type": "number",
"format": "float", # "format": "float",
"description": "Version of comms backbone message format protocol", # "description": "Version of comms backbone message format protocol",
"example": 2.0, # "example": 2.0,
}, # },
"source": { # "source": {
"type": "string", # "type": "string",
"description": "The sender; Where is this message from", # "description": "The sender; Where is this message from",
"example": "autonomy_engine", # "example": "autonomy_engine",
}, # },
"destination": { # "destination": {
"type": "string", # "type": "string",
"description": "Publisher topic; What is the destination" # "description": "Publisher topic; What is the destination"
+ " of this message", # + " of this message",
"example": "ah1", # "example": "ah1",
}, # },
"encoded": { # "encoded": {
"type": "boolean", # "type": "boolean",
"description": "Indicate that message raw (encoded) or decoded. " # "description": "Indicate that message raw (encoded) or decoded. "
+ "Options: encoded=True, decoded=False", # + "Options: encoded=True, decoded=False",
"example": False, # "example": False,
}, # },
"delivery_type": { # "delivery_type": {
"type": "string", # "type": "string",
"description": "To publish or broadcast this message.", # "description": "To publish or broadcast this message.",
"enum": ["broadcast", "publish"], # "enum": ["broadcast", "publish"],
"example": "publish", # "example": "publish",
"default": "publish", # "default": "publish",
}, # },
}, # },
"required": ["message_type"], # "required": ["message_type"],
} # }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
sent to the respective platform's C2 to compile into a platform-specific sent to the respective platform's C2 to compile into a platform-specific
mission plan. mission plan.
""" """
from formats import abstract_schema
action_schema = { action_schema = {
"type": "object", "type": "object",
...@@ -63,7 +64,6 @@ action_schema = { ...@@ -63,7 +64,6 @@ action_schema = {
} }
mission_plan_schema = { mission_plan_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"autonomy_engine_plan_ID": { "autonomy_engine_plan_ID": {
...@@ -84,3 +84,6 @@ mission_plan_schema = { ...@@ -84,3 +84,6 @@ mission_plan_schema = {
}, },
"required": ["plan_ID", "platform_ID", "plan"], "required": ["plan_ID", "platform_ID", "plan"],
} }
full_mission_plan_schema = abstract_schema
full_mission_plan_schema["properties"]["payload"] = mission_plan_schema
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
schema: Observation Message sent by platforms when points of schema: Observation Message sent by platforms when points of
interest are found. interest are found.
""" """
from formats import abstract_schema
hits_schema = { hits_schema = {
"type": "object", "type": "object",
...@@ -30,30 +31,38 @@ hits_schema = { ...@@ -30,30 +31,38 @@ hits_schema = {
} }
observation_schema = { observation_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"platform_ID": { "payload": {
"type": "integer", "type": "object",
"description": "ID of platform to sending observations", "properties": {
"example": 2, "platform_ID": {
}, "type": "integer",
"points_of_interest": { "description": "ID of platform to sending observations",
"type": "array", "example": 2,
"items": hits_schema, },
"description": "Points from features of interest identified by" "points_of_interest": {
+ " platform if any found.", # TODO: DEFINE FORMAT. "type": "array",
}, "items": hits_schema,
"region_surveyed": { "description": "Points from features of interest identified by"
"type": "null", + " platform if any found.", # TODO: DEFINE FORMAT.
"description": "Region surveyed by given platform." },
+ " GEOJSON", # TODO: DEFINE FORMAT. "region_surveyed": {
"example": "", # "type": "null",
}, "nullable": True,
"additional_data": { "description": "Region surveyed by given platform."
"description": "Placeholder field for any additional data", + " GEOJSON", # TODO: DEFINE FORMAT.
"example": {"sensor_payload": False}, "example": "",
},
"additional_data": {
"description": "Placeholder field for any additional data",
"example": {"sensor_payload": False},
},
},
}, },
}, },
"required": ["platform_ID"], "required": ["platform_ID"],
} }
full_observation_schema = abstract_schema
full_observation_schema["properties"]["payload"] = observation_schema
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
schemas: configuration sent to Autonomy Engine (i.e. during an emergency, schemas: configuration sent to Autonomy Engine (i.e. during an emergency,
if a platform needs to be removed from the mission planning) if a platform needs to be removed from the mission planning)
""" """
from formats import abstract_schema
emergency_schema = { emergency_schema = {
"type": "object", "type": "object",
...@@ -157,7 +158,6 @@ squad_metadata_schema = { ...@@ -157,7 +158,6 @@ squad_metadata_schema = {
} }
planning_configuration_schema = { planning_configuration_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"planning_config_ID": { "planning_config_ID": {
...@@ -182,3 +182,6 @@ planning_configuration_schema = { ...@@ -182,3 +182,6 @@ planning_configuration_schema = {
"exclusion_zones", "exclusion_zones",
], ],
} }
full_planning_configuration_schema = abstract_schema
full_planning_configuration_schema["properties"]["payload"] = planning_configuration_schema
""" """
schema: platform-specific decoded status message schema: platform-specific decoded status message
""" """
from formats import abstract_schema
sensor_schema = { sensor_schema = {
"type": "object", "type": "object",
"description": "Scanning sensor on platform available" "description": "Scanning sensor on platform available"
...@@ -26,7 +28,6 @@ sensor_schema = { ...@@ -26,7 +28,6 @@ sensor_schema = {
} }
platform_status_message_schema = { platform_status_message_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"platform_ID": { "platform_ID": {
...@@ -41,6 +42,14 @@ platform_status_message_schema = { ...@@ -41,6 +42,14 @@ platform_status_message_schema = {
+ " platform or USBL", + " platform or USBL",
"example": "usbl", "example": "usbl",
}, },
"transmission_mode": {
"type": "string",
"enum": ["acoustics", "iridium", "wifi", "starlink"],
"description": "Mode in which status message was transmitted"
+ " when on the surface (i.e. iridium/wifi) or underwater"
+ " (i.e. acoustics)",
"example": "wifi",
},
"platform_timestamp": { "platform_timestamp": {
"type": "string", "type": "string",
"format": "date-time", "format": "date-time",
...@@ -173,3 +182,7 @@ platform_status_message_schema = { ...@@ -173,3 +182,7 @@ platform_status_message_schema = {
"longitude", "longitude",
], ],
} }
full_platform_status_message_schema = abstract_schema
full_platform_status_message_schema["properties"]["payload"] = platform_status_message_schema
from formats.message_wrapper import message_wrapper_schema from formats import message_metadata
from formats.mission_plan import mission_plan_schema from formats.mission_plan import full_mission_plan_schema
from formats.observation import observation_schema from formats.observation import full_observation_schema
from formats.planning_configuration import planning_configuration_schema from formats.planning_configuration import full_planning_configuration_schema
from formats.platform_status import platform_status_message_schema from formats.platform_status import full_platform_status_message_schema
from formats.acknowledgement import acknowledgement_schema from formats.acknowledgement import full_acknowledgement_schema
from flasgger import Swagger from flasgger import Swagger
from flask import Flask from flask import Flask
...@@ -28,15 +28,15 @@ swagger_config = { ...@@ -28,15 +28,15 @@ swagger_config = {
"model_filter": lambda tag: True, "model_filter": lambda tag: True,
} }
], ],
"components": { # "components": {
"schemas": { "definitions": {
"Message": message_wrapper_schema, "Metadata": message_metadata,
"MissionPlan": mission_plan_schema, "MissionPlan": full_mission_plan_schema,
"Observation": observation_schema, "Observation": full_observation_schema,
"PlanningConfiguration": planning_configuration_schema, "PlanningConfiguration": full_planning_configuration_schema,
"PlatformStatus": platform_status_message_schema, "PlatformStatus": full_platform_status_message_schema,
"Acknowledgement": acknowledgement_schema, "Acknowledgement": full_acknowledgement_schema,
} # }
}, },
"paths": { "paths": {
"/all_messages": { "/all_messages": {
...@@ -49,26 +49,30 @@ swagger_config = { ...@@ -49,26 +49,30 @@ swagger_config = {
"application/json": { "application/json": {
"schema": { "schema": {
"oneOf": [ "oneOf": [
{ full_mission_plan_schema,
"$ref": "#/components/schemas/" full_planning_configuration_schema,
+ "Acknowledgement" full_platform_status_message_schema,
}, full_observation_schema,
{ # {
"$ref": "#/components/schemas/" # "$ref": "#/definitions/"
+ "MissionPlan" # + "Acknowledgement"
}, # },
{ # {
"$ref": "#/components/schemas/" # "$ref": "#/definitions/"
+ "Observation" # + "MissionPlan"
}, # },
{ # {
"$ref": "#/components/schemas/" # "$ref": "#/definitions/"
+ "PlanningConfiguration" # + "Observation"
}, # },
{ # {
"$ref": "#/components/schemas/" # "$ref": "#/definitions/"
+ "PlatformStatus" # + "PlanningConfiguration"
}, # },
# {
# "$ref": "#/definitions/"
# + "PlatformStatus"
# },
], ],
"discriminator": { "discriminator": {
"propertyName": "message_type", "propertyName": "message_type",
...@@ -85,8 +89,8 @@ swagger_config = { ...@@ -85,8 +89,8 @@ swagger_config = {
"consumes": ["application/json"], "consumes": ["application/json"],
} }
message_types = [ message_types = [
"Message", "Metadata",
"Acknowledgement", # "Acknowledgement",
"MissionPlan", "MissionPlan",
"Observation", "Observation",
"PlanningConfiguration", "PlanningConfiguration",
...@@ -104,7 +108,7 @@ for item in message_types: ...@@ -104,7 +108,7 @@ for item in message_types:
"schema": { "schema": {
"allOf": [ "allOf": [
{ {
"$ref": "#/components/schemas/" + item, "$ref": "#/definitions/" + item,
}, },
], ],
"discriminator": { "discriminator": {
......
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