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 @@
schemas: Acknowledgement status sent by the surface platform to report
receipt of message.
"""
# from openapi_schema_validator import validate
# from jsonschema import validate
acknowledgement_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"allOf": [{"$ref": "#/definitions/Message"}],
"type": "object",
"properties": {
"acknowledged_message_ID": {
......@@ -24,3 +28,8 @@ acknowledgement_schema = {
},
"required": ["acknowledged_message_ID", "status"],
}
# validate(
# {"acknowledged_message_ID": "string-type-id", "status": "c2_received"},
# acknowledgement_schema,
# )
......@@ -63,7 +63,7 @@ action_schema = {
}
mission_plan_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"allOf": [{"$ref": "#/definitions/Message"}],
"type": "object",
"properties": {
"autonomy_engine_plan_ID": {
......
......@@ -30,7 +30,7 @@ hits_schema = {
}
observation_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"allOf": [{"$ref": "#/definitions/Message"}],
"type": "object",
"properties": {
"platform_ID": {
......
......@@ -157,7 +157,7 @@ squad_metadata_schema = {
}
planning_configuration_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"allOf": [{"$ref": "#/definitions/Message"}],
"type": "object",
"properties": {
"planning_config_ID": {
......
......@@ -26,7 +26,7 @@ sensor_schema = {
}
platform_status_message_schema = {
"allOf": [{"$ref": "#/components/schemas/Message"}],
"allOf": [{"$ref": "#/definitions/Message"}],
"type": "object",
"properties": {
"platform_ID": {
......
from flask import Flask
from flasgger import Swagger
# from . import properties
from formats.message_wrapper import message_wrapper_schema
from formats.mission_plan import mission_plan_schema
from formats.observation import observation_schema
......@@ -9,11 +5,16 @@ 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
# from openapi_schema_validator import validate
from openapi_spec_validator import validate_spec_url
app = Flask(__name__)
swagger_config = {
"headers": [],
"openapi": "3.0.2",
"openapi": "3.1",
"swagger_ui": True,
"specs_route": "/",
"info": {
......@@ -29,15 +30,13 @@ swagger_config = {
"model_filter": lambda tag: True,
}
],
"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,
},
"definitions": {
"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": {
......@@ -50,30 +49,14 @@ swagger_config = {
"application/json": {
"schema": {
"oneOf": [
{"$ref": "#/definitions/Acknowledgement"},
{"$ref": "#/definitions/PlatformStatus"},
{"$ref": "#/definitions/MissionPlan"},
{"$ref": "#/definitions/Observation"},
{
"$ref": "#/components/"
+ "schemas/Acknowledgement"
},
{
"$ref": "#/components/"
+ "schemas/PlatformStatus"
},
{
"$ref": "#/components/"
+ "schemas/MissionPlan"
},
{
"$ref": "#/components/"
+ "schemas/Observation"
},
{
"$ref": "#/components/"
+ "schemas/PlanningConfiguration"
},
{
"$ref": "#/components/"
+ "schemas/PlatformStatus"
"$ref": "#/definitions/PlanningConfiguration"
},
{"$ref": "#/definitions/PlatformStatus"},
],
"discriminator": {
"propertyName": "message_type",
......@@ -90,7 +73,7 @@ swagger_config = {
"consumes": ["application/json"],
}
message_types = [
# "Message",
"Message",
"Acknowledgement",
"MissionPlan",
"Observation",
......@@ -109,7 +92,7 @@ for item in message_types:
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/" + item,
"$ref": "#/definitions/" + item,
},
],
"discriminator": {
......@@ -125,11 +108,23 @@ 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.
# 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