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

refactor: schemas and added abstract message

parent 806f47dc
......@@ -8,5 +8,5 @@
"encoded": false,
"message_type": "acknowledgement",
"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__ = [
for x in os.listdir(os.path.dirname(__file__))
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 @@
schemas: Acknowledgement status sent by the surface platform to report
receipt of message.
"""
# from openapi_schema_validator import validate
# from jsonschema import validate
from formats import abstract_schema
acknowledgement_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object",
"properties": {
"acknowledged_message_ID": {
......@@ -29,7 +26,5 @@ acknowledgement_schema = {
"required": ["acknowledged_message_ID", "status"],
}
# validate(
# {"acknowledged_message_ID": "string-type-id", "status": "c2_received"},
# acknowledgement_schema,
# )
full_acknowledgement_schema = abstract_schema
full_acknowledgement_schema["properties"]["payload"] = acknowledgement_schema
"""
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
destination and the type of message.
"""
# """
# 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
# destination and the type of message.
# """
message_wrapper_schema = {
"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"],
}
# message_wrapper_schema = {
# "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"],
# }
......@@ -3,6 +3,7 @@
sent to the respective platform's C2 to compile into a platform-specific
mission plan.
"""
from formats import abstract_schema
action_schema = {
"type": "object",
......@@ -63,7 +64,6 @@ action_schema = {
}
mission_plan_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object",
"properties": {
"autonomy_engine_plan_ID": {
......@@ -84,3 +84,6 @@ mission_plan_schema = {
},
"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 @@
schema: Observation Message sent by platforms when points of
interest are found.
"""
from formats import abstract_schema
hits_schema = {
"type": "object",
......@@ -30,30 +31,38 @@ hits_schema = {
}
observation_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object",
"properties": {
"platform_ID": {
"type": "integer",
"description": "ID of platform to sending observations",
"example": 2,
},
"points_of_interest": {
"type": "array",
"items": hits_schema,
"description": "Points from features of interest identified by"
+ " platform if any found.", # TODO: DEFINE FORMAT.
},
"region_surveyed": {
"type": "null",
"description": "Region surveyed by given platform."
+ " GEOJSON", # TODO: DEFINE FORMAT.
"example": "",
},
"additional_data": {
"description": "Placeholder field for any additional data",
"example": {"sensor_payload": False},
"payload": {
"type": "object",
"properties": {
"platform_ID": {
"type": "integer",
"description": "ID of platform to sending observations",
"example": 2,
},
"points_of_interest": {
"type": "array",
"items": hits_schema,
"description": "Points from features of interest identified by"
+ " platform if any found.", # TODO: DEFINE FORMAT.
},
"region_surveyed": {
# "type": "null",
"nullable": True,
"description": "Region surveyed by given platform."
+ " GEOJSON", # TODO: DEFINE FORMAT.
"example": "",
},
"additional_data": {
"description": "Placeholder field for any additional data",
"example": {"sensor_payload": False},
},
},
},
},
"required": ["platform_ID"],
}
full_observation_schema = abstract_schema
full_observation_schema["properties"]["payload"] = observation_schema
......@@ -2,6 +2,7 @@
schemas: configuration sent to Autonomy Engine (i.e. during an emergency,
if a platform needs to be removed from the mission planning)
"""
from formats import abstract_schema
emergency_schema = {
"type": "object",
......@@ -157,7 +158,6 @@ squad_metadata_schema = {
}
planning_configuration_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object",
"properties": {
"planning_config_ID": {
......@@ -182,3 +182,6 @@ planning_configuration_schema = {
"exclusion_zones",
],
}
full_planning_configuration_schema = abstract_schema
full_planning_configuration_schema["properties"]["payload"] = planning_configuration_schema
"""
schema: platform-specific decoded status message
"""
from formats import abstract_schema
sensor_schema = {
"type": "object",
"description": "Scanning sensor on platform available"
......@@ -26,7 +28,6 @@ sensor_schema = {
}
platform_status_message_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object",
"properties": {
"platform_ID": {
......@@ -41,6 +42,14 @@ platform_status_message_schema = {
+ " platform or 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": {
"type": "string",
"format": "date-time",
......@@ -173,3 +182,7 @@ platform_status_message_schema = {
"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.mission_plan import mission_plan_schema
from formats.observation import observation_schema
from formats.planning_configuration import planning_configuration_schema
from formats.platform_status import platform_status_message_schema
from formats.acknowledgement import acknowledgement_schema
from formats import message_metadata
from formats.mission_plan import full_mission_plan_schema
from formats.observation import full_observation_schema
from formats.planning_configuration import full_planning_configuration_schema
from formats.platform_status import full_platform_status_message_schema
from formats.acknowledgement import full_acknowledgement_schema
from flasgger import Swagger
from flask import Flask
......@@ -28,15 +28,15 @@ swagger_config = {
"model_filter": lambda tag: True,
}
],
"components": {
"schemas": {
"Message": message_wrapper_schema,
"MissionPlan": mission_plan_schema,
"Observation": observation_schema,
"PlanningConfiguration": planning_configuration_schema,
"PlatformStatus": platform_status_message_schema,
"Acknowledgement": acknowledgement_schema,
}
# "components": {
"definitions": {
"Metadata": message_metadata,
"MissionPlan": full_mission_plan_schema,
"Observation": full_observation_schema,
"PlanningConfiguration": full_planning_configuration_schema,
"PlatformStatus": full_platform_status_message_schema,
"Acknowledgement": full_acknowledgement_schema,
# }
},
"paths": {
"/all_messages": {
......@@ -49,26 +49,30 @@ swagger_config = {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/"
+ "Acknowledgement"
},
{
"$ref": "#/components/schemas/"
+ "MissionPlan"
},
{
"$ref": "#/components/schemas/"
+ "Observation"
},
{
"$ref": "#/components/schemas/"
+ "PlanningConfiguration"
},
{
"$ref": "#/components/schemas/"
+ "PlatformStatus"
},
full_mission_plan_schema,
full_planning_configuration_schema,
full_platform_status_message_schema,
full_observation_schema,
# {
# "$ref": "#/definitions/"
# + "Acknowledgement"
# },
# {
# "$ref": "#/definitions/"
# + "MissionPlan"
# },
# {
# "$ref": "#/definitions/"
# + "Observation"
# },
# {
# "$ref": "#/definitions/"
# + "PlanningConfiguration"
# },
# {
# "$ref": "#/definitions/"
# + "PlatformStatus"
# },
],
"discriminator": {
"propertyName": "message_type",
......@@ -85,8 +89,8 @@ swagger_config = {
"consumes": ["application/json"],
}
message_types = [
"Message",
"Acknowledgement",
"Metadata",
# "Acknowledgement",
"MissionPlan",
"Observation",
"PlanningConfiguration",
......@@ -104,7 +108,7 @@ for item in message_types:
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/" + item,
"$ref": "#/definitions/" + item,
},
],
"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