diff options
| author | Jan Friedli | 2020-07-14 15:28:08 +0200 |
|---|---|---|
| committer | Jan Friedli | 2020-07-14 15:28:08 +0200 |
| commit | 5d1e6b3235f9cddf66611e7cf4f4d0b41ffd7368 (patch) | |
| tree | dc95468b0d3ae3783560dfe3916b5dba2bf775ea /main.py | |
| parent | 42f9ede4bf9ee5cf0e7fda74fcd37bea5540c302 (diff) | |
upgrade to oas 3
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 25 |
1 files changed, 20 insertions, 5 deletions
| @@ -1,5 +1,6 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import jinja2 | 2 | import jinja2 |
| 3 | import yaml | ||
| 3 | 4 | ||
| 4 | from matweb import utils, rest_api, frontend | 5 | from matweb import utils, rest_api, frontend |
| 5 | from flask import Flask, request | 6 | from flask import Flask, request |
| @@ -30,17 +31,31 @@ def create_app(test_config=None): | |||
| 30 | app.register_blueprint(rest_api.api_bp) | 31 | app.register_blueprint(rest_api.api_bp) |
| 31 | app.json_encoder = LazyJSONEncoder | 32 | app.json_encoder = LazyJSONEncoder |
| 32 | 33 | ||
| 34 | dirname = os.path.dirname(__file__) | ||
| 35 | with open(os.path.join(dirname, 'matweb/oas/components.yml')) as file: | ||
| 36 | components = yaml.full_load(file) | ||
| 37 | |||
| 33 | template = dict( | 38 | template = dict( |
| 34 | schemes=['https', 'http'], | 39 | servers=[ |
| 35 | host=LazyString(lambda: request.host), | 40 | { |
| 36 | basePath='/', | 41 | 'url': LazyString(lambda: request.host_url), |
| 42 | 'description': 'References the current running server' | ||
| 43 | } | ||
| 44 | ], | ||
| 37 | info={ | 45 | info={ |
| 38 | 'title': 'Mat2 Web API', | 46 | 'title': 'Mat2 Web API', |
| 39 | 'version': '1', | 47 | 'version': '1', |
| 40 | 'description': 'Mat2 Web RESTful API documentation', | 48 | 'description': 'Mat2 Web RESTful API documentation', |
| 41 | } | 49 | }, |
| 50 | components=components | ||
| 42 | ) | 51 | ) |
| 43 | Swagger(app, template=template) | 52 | swagger_config = Swagger.DEFAULT_CONFIG |
| 53 | swagger_config['swagger_ui_bundle_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js' | ||
| 54 | swagger_config['swagger_ui_standalone_preset_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js' | ||
| 55 | swagger_config['swagger_ui_css'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui.css' | ||
| 56 | swagger_config['openapi'] = "3.0.3" | ||
| 57 | Swagger(app, template=template, config=swagger_config) | ||
| 58 | |||
| 44 | CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}}) | 59 | CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}}) |
| 45 | 60 | ||
| 46 | return app | 61 | return app |
