Commit 231dca1e authored by Trishna Saeharaseelan's avatar Trishna Saeharaseelan
Browse files

refactor(specs): replace components/schemas to definitions

parent 1b8ad63e
formats/__pycache__
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
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 jsonschema import validate
acknowledgement_schema = { acknowledgement_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}], "allOf": [{"$ref": "#/definitions/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"acknowledged_message_ID": { "acknowledged_message_ID": {
...@@ -24,3 +28,8 @@ acknowledgement_schema = { ...@@ -24,3 +28,8 @@ acknowledgement_schema = {
}, },
"required": ["acknowledged_message_ID", "status"], "required": ["acknowledged_message_ID", "status"],
} }
# validate(
# {"acknowledged_message_ID": "string-type-id", "status": "c2_received"},
# acknowledgement_schema,
# )
...@@ -63,7 +63,7 @@ action_schema = { ...@@ -63,7 +63,7 @@ action_schema = {
} }
mission_plan_schema = { mission_plan_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}], "allOf": [{"$ref": "#/definitions/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"autonomy_engine_plan_ID": { "autonomy_engine_plan_ID": {
......
...@@ -30,7 +30,7 @@ hits_schema = { ...@@ -30,7 +30,7 @@ hits_schema = {
} }
observation_schema = { observation_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}], "allOf": [{"$ref": "#/definitions/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"platform_ID": { "platform_ID": {
......
...@@ -157,7 +157,7 @@ squad_metadata_schema = { ...@@ -157,7 +157,7 @@ squad_metadata_schema = {
} }
planning_configuration_schema = { planning_configuration_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}], "allOf": [{"$ref": "#/definitions/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"planning_config_ID": { "planning_config_ID": {
......
...@@ -26,7 +26,7 @@ sensor_schema = { ...@@ -26,7 +26,7 @@ sensor_schema = {
} }
platform_status_message_schema = { platform_status_message_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}], "allOf": [{"$ref": "#/definitions/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"platform_ID": { "platform_ID": {
......
from flask import Flask
from flasgger import Swagger
# from . import properties
from formats.message_wrapper import message_wrapper_schema from formats.message_wrapper import message_wrapper_schema
from formats.mission_plan import mission_plan_schema from formats.mission_plan import mission_plan_schema
from formats.observation import observation_schema from formats.observation import observation_schema
...@@ -9,11 +5,16 @@ from formats.planning_configuration import planning_configuration_schema ...@@ -9,11 +5,16 @@ from formats.planning_configuration import planning_configuration_schema
from formats.platform_status import platform_status_message_schema from formats.platform_status import platform_status_message_schema
from formats.acknowledgement import acknowledgement_schema from formats.acknowledgement import acknowledgement_schema
from flasgger import Swagger
from flask import Flask
# from openapi_schema_validator import validate
from openapi_spec_validator import validate_spec_url
app = Flask(__name__) app = Flask(__name__)
swagger_config = { swagger_config = {
"headers": [], "headers": [],
"openapi": "3.0.2", "openapi": "3.1",
"swagger_ui": True, "swagger_ui": True,
"specs_route": "/", "specs_route": "/",
"info": { "info": {
...@@ -29,15 +30,13 @@ swagger_config = { ...@@ -29,15 +30,13 @@ swagger_config = {
"model_filter": lambda tag: True, "model_filter": lambda tag: True,
} }
], ],
"components": { "definitions": {
"schemas": { "Message": message_wrapper_schema,
"Message": message_wrapper_schema, "MissionPlan": mission_plan_schema,
"MissionPlan": mission_plan_schema, "Observation": observation_schema,
"Observation": observation_schema, "PlanningConfiguration": planning_configuration_schema,
"PlanningConfiguration": planning_configuration_schema, "PlatformStatus": platform_status_message_schema,
"PlatformStatus": platform_status_message_schema, "Acknowledgement": acknowledgement_schema,
"Acknowledgement": acknowledgement_schema,
},
}, },
"paths": { "paths": {
"/all_messages": { "/all_messages": {
...@@ -50,30 +49,14 @@ swagger_config = { ...@@ -50,30 +49,14 @@ swagger_config = {
"application/json": { "application/json": {
"schema": { "schema": {
"oneOf": [ "oneOf": [
{"$ref": "#/definitions/Acknowledgement"},
{"$ref": "#/definitions/PlatformStatus"},
{"$ref": "#/definitions/MissionPlan"},
{"$ref": "#/definitions/Observation"},
{ {
"$ref": "#/components/" "$ref": "#/definitions/PlanningConfiguration"
+ "schemas/Acknowledgement"
},
{
"$ref": "#/components/"
+ "schemas/PlatformStatus"
},
{
"$ref": "#/components/"
+ "schemas/MissionPlan"
},
{
"$ref": "#/components/"
+ "schemas/Observation"
},
{
"$ref": "#/components/"
+ "schemas/PlanningConfiguration"
},
{
"$ref": "#/components/"
+ "schemas/PlatformStatus"
}, },
{"$ref": "#/definitions/PlatformStatus"},
], ],
"discriminator": { "discriminator": {
"propertyName": "message_type", "propertyName": "message_type",
...@@ -90,7 +73,7 @@ swagger_config = { ...@@ -90,7 +73,7 @@ swagger_config = {
"consumes": ["application/json"], "consumes": ["application/json"],
} }
message_types = [ message_types = [
# "Message", "Message",
"Acknowledgement", "Acknowledgement",
"MissionPlan", "MissionPlan",
"Observation", "Observation",
...@@ -109,7 +92,7 @@ for item in message_types: ...@@ -109,7 +92,7 @@ for item in message_types:
"schema": { "schema": {
"allOf": [ "allOf": [
{ {
"$ref": "#/components/schemas/" + item, "$ref": "#/definitions/" + item,
}, },
], ],
"discriminator": { "discriminator": {
...@@ -125,11 +108,23 @@ for item in message_types: ...@@ -125,11 +108,23 @@ for item in message_types:
swag = Swagger(app, config=swagger_config, merge=True) swag = Swagger(app, config=swagger_config, merge=True)
# validate({"acknowledged_message_ID": "string-type-id", "status": "c2_received"}, acknowledgement_schema)
# app.add_url_rule( # app.add_url_rule(
# '/coordinates', # '/coordinates',
# view_func=Coordinates.as_view('coordinates'), # view_func=Coordinates.as_view('coordinates'),
# methods=['GET'] # methods=['GET']
# ) # )
from openapi_spec_validator import validate_spec, openapi_v3_spec_validator
if __name__ == "__main__": if __name__ == "__main__":
app.run(debug=True) app.run(debug=True)
# print(validate_spec_url("http://127.0.0.1:5000/swagger.json"))
# If no exception is raised by validate_spec(), the spec is valid.
# validate_spec(swagger_config)
# print("000 Schema validation passed")
# errors_iterator = openapi_v3_spec_validator.iter_errors(swagger_config)
# print(errors_iterator)
\ No newline at end of file
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