From 5d1e6b3235f9cddf66611e7cf4f4d0b41ffd7368 Mon Sep 17 00:00:00 2001 From: Jan Friedli Date: Tue, 14 Jul 2020 15:28:08 +0200 Subject: upgrade to oas 3 --- main.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index 74a03fc..2fc23b1 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import os import jinja2 +import yaml from matweb import utils, rest_api, frontend from flask import Flask, request @@ -30,17 +31,31 @@ def create_app(test_config=None): app.register_blueprint(rest_api.api_bp) app.json_encoder = LazyJSONEncoder + dirname = os.path.dirname(__file__) + with open(os.path.join(dirname, 'matweb/oas/components.yml')) as file: + components = yaml.full_load(file) + template = dict( - schemes=['https', 'http'], - host=LazyString(lambda: request.host), - basePath='/', + servers=[ + { + 'url': LazyString(lambda: request.host_url), + 'description': 'References the current running server' + } + ], info={ 'title': 'Mat2 Web API', 'version': '1', 'description': 'Mat2 Web RESTful API documentation', - } + }, + components=components ) - Swagger(app, template=template) + swagger_config = Swagger.DEFAULT_CONFIG + swagger_config['swagger_ui_bundle_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js' + swagger_config['swagger_ui_standalone_preset_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js' + swagger_config['swagger_ui_css'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui.css' + swagger_config['openapi'] = "3.0.3" + Swagger(app, template=template, config=swagger_config) + CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}}) return app -- cgit v1.3