From 48dae8badfcc3ff379f2bedb7839cc7fe69ddbfd Mon Sep 17 00:00:00 2001 From: guille Date: Tue, 24 Jan 2023 05:38:45 -0500 Subject: [PATCH] Playing around with the yml file --- bootstrap.py | 45 +++++++++++++++------------------- hub_api/docs/openapi-specs.yml | 37 ++++++++++++++++++++++++++++ hub_api/docs/uptime.yml | 0 hub_api/uptime.py | 2 -- 4 files changed, 57 insertions(+), 27 deletions(-) delete mode 100644 hub_api/docs/uptime.yml diff --git a/bootstrap.py b/bootstrap.py index 3a0361a..4b8c44f 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -9,10 +9,9 @@ import datetime import flask import yaml -from flasgger import LazyJSONEncoder, Swagger +from flasgger import LazyJSONEncoder, Swagger, swag_from from flask import Response, jsonify from flask_restful import Api -from flask_swagger import swagger import hub_api.helpers.session_helper as sh from hub_api.construction_catalog import ConstructionCatalogEntry, ConstructionCatalogEntries, ConstructionCatalogNames @@ -27,26 +26,6 @@ app = flask.Flask('cerc_api') app.json_provider_class = LazyJSONEncoder api = Api(app) -with open("hub_api/docs/openapi-specs.yml", "r") as stream: - swagger_config = { - "headers": [], - "specs": [ - { - "endpoint": 'apispec', - "route": '/apispec.json', - "rule_filter": lambda rule: True, # all in - "model_filter": lambda tag: True, # all in - } - ], - "static_url_path": "/flasgger_static", - "specs_route": "/api-docs/", - "openapi": "3.0.0" - } - try: - sh.swagger_data = Swagger(app, template=yaml.safe_load(stream), config=swagger_config) - except yaml.YAMLError as exc: - print(exc) - api.add_resource(Uptime, '/v1.4/uptime') # Catalogs. @@ -67,10 +46,26 @@ api.add_resource(SessionStart, '/v1.4/session/start') api.add_resource(SessionEnd, '/v1.4/session/end') api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive') -@app.route("/v1.4/spec") -def spec(): +with open("hub_api/docs/openapi-specs.yml", "r") as stream: + swagger_config = { + "headers": [], + "specs": [ + { + "endpoint": 'apispec', + "route": '/apispec.json', + "rule_filter": lambda rule: True, # all in + "model_filter": lambda tag: True, # all in + } + ], + "static_url_path": "/flasgger_static", + "specs_route": "/v1.4/api-docs/", + "openapi": "3.0.0" + } + try: + Swagger(app, template=yaml.safe_load(stream), config=swagger_config) + except yaml.YAMLError as exc: + print(exc) - return jsonify(sh.swagger_data.config) @app.route("/") def home(): diff --git a/hub_api/docs/openapi-specs.yml b/hub_api/docs/openapi-specs.yml index b467622..ad76cf4 100644 --- a/hub_api/docs/openapi-specs.yml +++ b/hub_api/docs/openapi-specs.yml @@ -9,6 +9,37 @@ externalDocs: description: Find out more about Swagger url: http://swagger.io paths: + /v1.4/uptime: + get: + tags: + - Uptime + summary: API uptime + operationId: uptime + description: Retrieve current API uptime + parameters: + - in: header + name: appId + schema: + type: string + required: true + description: the Id of the application access this API + requestBody: + description: Current uptime for the API instance. + content: + application/json: + schema: + $ref: '#/components/schemas/Uptime' + application/xml: + schema: + $ref: '#/components/schemas/Uptime' + responses: + '200': + description: Request sucessful + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + /v1.4/city: post: tags: @@ -571,6 +602,12 @@ paths: - BearerAuth: [ ] components: schemas: + Uptime: + type: json + propreties: + uptime: time + format: hh:mm:ss.ms + example: 0:09:53.600281 City: type: object properties: diff --git a/hub_api/docs/uptime.yml b/hub_api/docs/uptime.yml deleted file mode 100644 index e69de29..0000000 diff --git a/hub_api/uptime.py b/hub_api/uptime.py index 52fb302..9fabd35 100644 --- a/hub_api/uptime.py +++ b/hub_api/uptime.py @@ -7,13 +7,11 @@ Copyright © 2022 Project Author name guillermo.gutierrezmorote@concordia.ca import datetime import json -from flasgger import swag_from from flask import Response from flask_restful import Resource import hub_api.helpers.session_helper as sh -@swag_from('docs/uptime.yml') class Uptime(Resource): def __init__(self): pass