Skip to content
Snippets Groups Projects
Commit 387a55ee authored by Robert Goldmann's avatar Robert Goldmann
Browse files

serve open api swagger docs

parent 1080cf8b
No related branches found
No related tags found
No related merge requests found
......@@ -16,5 +16,6 @@ flask = "==1.1.2"
gevent = "==20.9.0"
TheCodeLabs-BaseUtils = "*"
TheCodeLabs-FlaskUtils = "*"
pyyaml = "==5.3.1"
[dev-packages]
This diff is collapsed.
......@@ -14,7 +14,7 @@ class StorageLeaf(FlaskBaseApp):
super().__init__(appName, os.path.dirname(__file__), LOGGER, serveRobotsTxt=False)
def _register_blueprints(self, app):
app.register_blueprint(Routes.construct_blueprint(self._settings))
app.register_blueprint(Routes.construct_blueprint(self._settings, self._version))
return app
......
import json
import os
from enum import Enum
from flask import Blueprint, request, jsonify
import yaml
from flask import Blueprint, request, jsonify, send_from_directory, render_template
from logic import Constants
from logic.Database import Database
from logic.RequestValidator import ValidationError, RequestValidator
......@@ -24,12 +28,22 @@ class SensorParameters(Enum):
return [m.value for m in SensorParameters]
def construct_blueprint(settings):
def construct_blueprint(settings, version):
routes = Blueprint('routes', __name__)
@routes.route('/', methods=['GET'])
def index():
return "Hello World!"
yamlPath = os.path.join(Constants.ROOT_DIR, 'docs', 'api.yml')
with open(yamlPath, 'r') as yamlFile:
specification = yaml.load(yamlFile, Loader=yaml.FullLoader)
specification['servers'][0]['url'] = '0815'
specification['info']['version'] = version['name']
specification = json.dumps(specification)
return render_template('api.html',
appName=Constants.APP_NAME,
openApiSpecification=specification)
@routes.route('/device/<deviceName>', methods=['POST'])
def postSensorData(deviceName):
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ appName }} API</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.22.2/swagger-ui.css" >
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after
{
box-sizing: inherit;
}
body {
margin:0;
background: #fafafa;
}
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.22.2/swagger-ui-bundle.js"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.22.2/swagger-ui-standalone-preset.js"> </script>
<script>
window.onload = function() {
var spec = {{ openApiSpecification|safe }};
// Build a system
const ui = SwaggerUIBundle({
spec: spec,
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis
]
})
window.ui = ui
}
</script>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment