generate_schema_config.py 3.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
from formats import message_header
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 flasgger import Swagger
from flask import Flask

app = Flask(__name__)


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",
        }
    ],
    "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"
                    },
                },
                "required": ["header", "payload"],
            },
            "payload": {
                "discriminator": {
                    "propertyName": "message_type",
                    "mapping":{
49 50 51 52 53
                        "mission_plan": "#/components/schemas/mission_plan",
                        "observation": "#/components/schemas/observation",
                        "planning_configuration": "#/components/schemas/planning_configuration",
                        "platform_status": "#/components/schemas/platform_status",
                        "acknowledgement": "#/components/schemas/acknowledgement",
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
                    },
                },
                "oneOf":[
                    {
                        "$ref": "#/components/schemas/"
                        + "acknowledgement"
                    },
                    {
                        "$ref": "#/components/schemas/"
                        + "mission_plan"
                    },
                    {
                        "$ref": "#/components/schemas/"
                        + "observation"
                    },
                    {
                        "$ref": "#/components/schemas/"
                        + "planning_configuration"
                    },
                    {
                        "$ref": "#/components/schemas/"
                        + "platform_status"
                    },
                ]
            },
            "header": message_header,
            "mission_plan": mission_plan_schema,
            "observation": observation_schema,
            "planning_configuration": planning_configuration_schema,
            "platform_status": platform_status_message_schema,
            "acknowledgement": acknowledgement_schema,
        }
    },
}

swag = Swagger(app, config=swagger_config, merge=True)


if __name__ == "__main__":
    app.run(debug=True)