summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Friedli2020-07-13 16:01:32 +0200
committerJan Friedli2020-07-13 16:01:32 +0200
commit37469e3e080952fdb21cefdce2346fd727990850 (patch)
tree566c2c22804793935a8273f59fb3de1beb2d36d0
parentd6001d0f2575bc4e171a24132124a20f7dbaeae7 (diff)
get schema values dynamically
-rw-r--r--main.py24
-rw-r--r--matweb/rest_api.py4
2 files changed, 18 insertions, 10 deletions
diff --git a/main.py b/main.py
index 6038013..63f680c 100644
--- a/main.py
+++ b/main.py
@@ -2,9 +2,9 @@ import os
2import jinja2 2import jinja2
3 3
4from matweb import utils, rest_api, frontend 4from matweb import utils, rest_api, frontend
5from flask import Flask 5from flask import Flask, request
6from flask_cors import CORS 6from flask_cors import CORS
7from flasgger import Swagger 7from flasgger import Swagger, LazyString, LazyJSONEncoder
8 8
9 9
10def create_app(test_config=None): 10def create_app(test_config=None):
@@ -13,11 +13,6 @@ def create_app(test_config=None):
13 app.config['UPLOAD_FOLDER'] = os.environ.get('MAT2_WEB_DOWNLOAD_FOLDER', './uploads/') 13 app.config['UPLOAD_FOLDER'] = os.environ.get('MAT2_WEB_DOWNLOAD_FOLDER', './uploads/')
14 app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB 14 app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB
15 app.config['CUSTOM_TEMPLATES_DIR'] = 'custom_templates' 15 app.config['CUSTOM_TEMPLATES_DIR'] = 'custom_templates'
16 app.config['SWAGGER'] = {
17 'title': 'Mat2 Web API',
18 'version': '1.0.0',
19 'basePath': '/api'
20 }
21 # optionally load settings from config.py 16 # optionally load settings from config.py
22 app.config.from_object('config') 17 app.config.from_object('config')
23 18
@@ -33,7 +28,20 @@ def create_app(test_config=None):
33 28
34 # Restful API hookup 29 # Restful API hookup
35 app.register_blueprint(rest_api.api_bp) 30 app.register_blueprint(rest_api.api_bp)
36 Swagger(app) 31 app.json_encoder = LazyJSONEncoder
32
33 template = dict(
34 swaggerUiPrefix=LazyString(lambda: request.environ.get('HTTP_X_SCRIPT_NAME', '')),
35 schemes=[LazyString(lambda: 'https' if request.is_secure else 'http')],
36 version='1',
37 host=LazyString(lambda: request.host),
38 info={
39 'title': 'Mat2 Web API',
40 'version': '1',
41 'description': 'Mat2 Web RESTful API documentation',
42 }
43 )
44 Swagger(app, template=template)
37 CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}}) 45 CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}})
38 46
39 return app 47 return app
diff --git a/matweb/rest_api.py b/matweb/rest_api.py
index 4910b44..429b82e 100644
--- a/matweb/rest_api.py
+++ b/matweb/rest_api.py
@@ -15,8 +15,8 @@ from flasgger import swag_from
15from matweb import file_removal_scheduler, utils 15from matweb import file_removal_scheduler, utils
16 16
17 17
18api_bp = Blueprint('api_bp', __name__, url_prefix='/api/') 18api_bp = Blueprint('api_bp', __name__)
19api = Api(api_bp) 19api = Api(api_bp, prefix='/api')
20 20
21 21
22class APIUpload(Resource): 22class APIUpload(Resource):