From 4c0a0aba427e87678d04e9ee238faf028971fabf Mon Sep 17 00:00:00 2001
From: Trishna Saeharaseelan <trishna.saeharaseelan@noc.ac.uk>
Date: Mon, 23 Jan 2023 19:34:16 +0800
Subject: [PATCH] refactor: temp revert to components/schemas

---
 formats/__init__.py |  2 +-
 generate_swagger.py | 64 +++++++++++++++++++++------------------------
 2 files changed, 31 insertions(+), 35 deletions(-)

diff --git a/formats/__init__.py b/formats/__init__.py
index 79f2ec5..5254584 100644
--- a/formats/__init__.py
+++ b/formats/__init__.py
@@ -8,7 +8,7 @@ __all__ = [
 ]
 
 abstract_schema = {
-    "allOf": [{"$ref": "#/definitions/Metadata"}],
+    "allOf": [{"$ref": "#/components/schemas/Metadata"}],
     "type": "object",
     "properties": {
         "payload": {}
diff --git a/generate_swagger.py b/generate_swagger.py
index 5820cdc..a30a9f0 100644
--- a/generate_swagger.py
+++ b/generate_swagger.py
@@ -28,15 +28,15 @@ swagger_config = {
             "model_filter": lambda tag: True,
         }
     ],
-    # "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,
-    # }
+    "components": {
+        "schemas": {
+            "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,30 +49,26 @@ swagger_config = {
                             "application/json": {
                                 "schema": {
                                     "oneOf": [
-                                        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"
-                                        # },
+                                        {
+                                            "$ref": "#/components/schemas/"
+                                            + "Acknowledgement"
+                                        },
+                                        {
+                                            "$ref": "#/components/schemas/"
+                                            + "MissionPlan"
+                                        },
+                                        {
+                                            "$ref": "#/components/schemas/"
+                                            + "Observation"
+                                        },
+                                        {
+                                            "$ref": "#/components/schemas/"
+                                            + "PlanningConfiguration"
+                                        },
+                                        {
+                                            "$ref": "#/components/schemas/"
+                                            + "PlatformStatus"
+                                        },
                                     ],
                                     "discriminator": {
                                         "propertyName": "message_type",
@@ -108,7 +104,7 @@ for item in message_types:
                             "schema": {
                                 "allOf": [
                                     {
-                                        "$ref": "#/definitions/" + item,
+                                        "$ref": "#/components/schemas/" + item,
                                     },
                                 ],
                                 "discriminator": {
-- 
GitLab