Playing around with the yml file
This commit is contained in:
parent
d4e444e3e7
commit
48dae8badf
45
bootstrap.py
45
bootstrap.py
@ -9,10 +9,9 @@ import datetime
|
|||||||
|
|
||||||
import flask
|
import flask
|
||||||
import yaml
|
import yaml
|
||||||
from flasgger import LazyJSONEncoder, Swagger
|
from flasgger import LazyJSONEncoder, Swagger, swag_from
|
||||||
from flask import Response, jsonify
|
from flask import Response, jsonify
|
||||||
from flask_restful import Api
|
from flask_restful import Api
|
||||||
from flask_swagger import swagger
|
|
||||||
|
|
||||||
import hub_api.helpers.session_helper as sh
|
import hub_api.helpers.session_helper as sh
|
||||||
from hub_api.construction_catalog import ConstructionCatalogEntry, ConstructionCatalogEntries, ConstructionCatalogNames
|
from hub_api.construction_catalog import ConstructionCatalogEntry, ConstructionCatalogEntries, ConstructionCatalogNames
|
||||||
@ -27,26 +26,6 @@ app = flask.Flask('cerc_api')
|
|||||||
app.json_provider_class = LazyJSONEncoder
|
app.json_provider_class = LazyJSONEncoder
|
||||||
api = Api(app)
|
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')
|
api.add_resource(Uptime, '/v1.4/uptime')
|
||||||
|
|
||||||
# Catalogs.
|
# Catalogs.
|
||||||
@ -67,10 +46,26 @@ api.add_resource(SessionStart, '/v1.4/session/start')
|
|||||||
api.add_resource(SessionEnd, '/v1.4/session/end')
|
api.add_resource(SessionEnd, '/v1.4/session/end')
|
||||||
api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive')
|
api.add_resource(KeepSessionAlive, '/v1.4/session/keep_alive')
|
||||||
|
|
||||||
@app.route("/v1.4/spec")
|
with open("hub_api/docs/openapi-specs.yml", "r") as stream:
|
||||||
def spec():
|
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("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
|
@ -9,6 +9,37 @@ externalDocs:
|
|||||||
description: Find out more about Swagger
|
description: Find out more about Swagger
|
||||||
url: http://swagger.io
|
url: http://swagger.io
|
||||||
paths:
|
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:
|
/v1.4/city:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
@ -571,6 +602,12 @@ paths:
|
|||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
components:
|
components:
|
||||||
schemas:
|
schemas:
|
||||||
|
Uptime:
|
||||||
|
type: json
|
||||||
|
propreties:
|
||||||
|
uptime: time
|
||||||
|
format: hh:mm:ss.ms
|
||||||
|
example: 0:09:53.600281
|
||||||
City:
|
City:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
@ -7,13 +7,11 @@ Copyright © 2022 Project Author name guillermo.gutierrezmorote@concordia.ca
|
|||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from flasgger import swag_from
|
|
||||||
from flask import Response
|
from flask import Response
|
||||||
from flask_restful import Resource
|
from flask_restful import Resource
|
||||||
|
|
||||||
import hub_api.helpers.session_helper as sh
|
import hub_api.helpers.session_helper as sh
|
||||||
|
|
||||||
@swag_from('docs/uptime.yml')
|
|
||||||
class Uptime(Resource):
|
class Uptime(Resource):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user