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 @@
acknowledgement_schema = {
"allOf": [{"$ref": "#/definitions/Message"}],
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object",
"properties": {
"acknowledged_message_ID": {
......
......@@ -63,7 +63,7 @@ action_schema = {
}
mission_plan_schema = {
"allOf": [{"$ref": "#/definitions/Message"}],
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object",
"properties": {
"autonomy_engine_plan_ID": {
......
......@@ -30,7 +30,7 @@ hits_schema = {
}
observation_schema = {
"allOf": [{"$ref": "#/definitions/Message"}],
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object",
"properties": {
"platform_ID": {
......
......@@ -157,7 +157,7 @@ squad_metadata_schema = {
}
planning_configuration_schema = {
"allOf": [{"$ref": "#/definitions/Message"}],
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object",
"properties": {
"planning_config_ID": {
......
......@@ -26,7 +26,7 @@ sensor_schema = {
}
platform_status_message_schema = {
"allOf": [{"$ref": "#/definitions/Message"}],
"allOf": [{"$ref": "#/components/schemas/Message"}],
"type": "object",
"properties": {
"platform_ID": {
......
......@@ -7,14 +7,12 @@ 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__)
swagger_config = {
"headers": [],
"openapi": "3.1",
"openapi": "3.0.2",
"swagger_ui": True,
"specs_route": "/",
"info": {
......@@ -30,13 +28,15 @@ swagger_config = {
"model_filter": lambda tag: True,
}
],
"definitions": {
"Message": message_wrapper_schema,
"MissionPlan": mission_plan_schema,
"Observation": observation_schema,
"PlanningConfiguration": planning_configuration_schema,
"PlatformStatus": platform_status_message_schema,
"Acknowledgement": acknowledgement_schema,
"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,
}
},
"paths": {
"/all_messages": {
......@@ -49,14 +49,26 @@ swagger_config = {
"application/json": {
"schema": {
"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": {
"propertyName": "message_type",
......@@ -92,7 +104,7 @@ for item in message_types:
"schema": {
"allOf": [
{
"$ref": "#/definitions/" + item,
"$ref": "#/components/schemas/" + item,
},
],
"discriminator": {
......@@ -108,23 +120,14 @@ for item in message_types:
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__":
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.
# # 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
# print(errors_iterator)
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