Commit 806f47dc authored by Trishna Saeharaseelan's avatar Trishna Saeharaseelan
Browse files

refactor(specs): revert definitions back to components/schemas

parent 231dca1e
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
acknowledgement_schema = { acknowledgement_schema = {
"allOf": [{"$ref": "#/definitions/Message"}], "allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"acknowledged_message_ID": { "acknowledged_message_ID": {
......
...@@ -63,7 +63,7 @@ action_schema = { ...@@ -63,7 +63,7 @@ action_schema = {
} }
mission_plan_schema = { mission_plan_schema = {
"allOf": [{"$ref": "#/definitions/Message"}], "allOf": [{"$ref": "#/components/schemas/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": "#/definitions/Message"}], "allOf": [{"$ref": "#/components/schemas/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": "#/definitions/Message"}], "allOf": [{"$ref": "#/components/schemas/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": "#/definitions/Message"}], "allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object", "type": "object",
"properties": { "properties": {
"platform_ID": { "platform_ID": {
......
...@@ -7,14 +7,12 @@ from formats.acknowledgement import acknowledgement_schema ...@@ -7,14 +7,12 @@ from formats.acknowledgement import acknowledgement_schema
from flasgger import Swagger from flasgger import Swagger
from flask import Flask 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.1", "openapi": "3.0.2",
"swagger_ui": True, "swagger_ui": True,
"specs_route": "/", "specs_route": "/",
"info": { "info": {
...@@ -30,13 +28,15 @@ swagger_config = { ...@@ -30,13 +28,15 @@ swagger_config = {
"model_filter": lambda tag: True, "model_filter": lambda tag: True,
} }
], ],
"definitions": { "components": {
"Message": message_wrapper_schema, "schemas": {
"MissionPlan": mission_plan_schema, "Message": message_wrapper_schema,
"Observation": observation_schema, "MissionPlan": mission_plan_schema,
"PlanningConfiguration": planning_configuration_schema, "Observation": observation_schema,
"PlatformStatus": platform_status_message_schema, "PlanningConfiguration": planning_configuration_schema,
"Acknowledgement": acknowledgement_schema, "PlatformStatus": platform_status_message_schema,
"Acknowledgement": acknowledgement_schema,
}
}, },
"paths": { "paths": {
"/all_messages": { "/all_messages": {
...@@ -49,14 +49,26 @@ swagger_config = { ...@@ -49,14 +49,26 @@ swagger_config = {
"application/json": { "application/json": {
"schema": { "schema": {
"oneOf": [ "oneOf": [
{"$ref": "#/definitions/Acknowledgement"},
{"$ref": "#/definitions/PlatformStatus"},
{"$ref": "#/definitions/MissionPlan"},
{"$ref": "#/definitions/Observation"},
{ {
"$ref": "#/definitions/PlanningConfiguration" "$ref": "#/components/schemas/"
+ "Acknowledgement"
},
{
"$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",
...@@ -92,7 +104,7 @@ for item in message_types: ...@@ -92,7 +104,7 @@ for item in message_types:
"schema": { "schema": {
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/" + item, "$ref": "#/components/schemas/" + item,
}, },
], ],
"discriminator": { "discriminator": {
...@@ -108,23 +120,14 @@ for item in message_types: ...@@ -108,23 +120,14 @@ 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(
# '/coordinates',
# view_func=Coordinates.as_view('coordinates'),
# 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")) # print(validate_spec_url("http://127.0.0.1:5000/swagger.json"))
# If no exception is raised by validate_spec(), the spec is valid. # # If no exception is raised by validate_spec(), the spec is valid.
# validate_spec(swagger_config) # validate_spec(swagger_config)
# print("000 Schema validation passed") # print("000 Schema validation passed")
# errors_iterator = openapi_v3_spec_validator.iter_errors(swagger_config) # errors_iterator = openapi_v3_spec_validator.iter_errors(swagger_config)
# print(errors_iterator) # 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