-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPI_main.py
More file actions
42 lines (32 loc) · 1.27 KB
/
Copy pathAPI_main.py
File metadata and controls
42 lines (32 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import os
import connexion
from flask import send_from_directory
from flask_cors import CORS
import swagger_server
from swagger_server import encoder
def main():
# swagger_url => path to ui
options = {'swagger_url': '/'}
app = connexion.App(__name__, specification_dir='swagger/', options=options)
app.app.json_encoder = encoder.JSONEncoder
app.add_api('swagger.yaml', arguments={'title': 'API RDcode'}, pythonic_params=True)
# manual override of the API_contract url, comment to return to default. cf templates/index.j2
app.app.jinja_env.globals['workaround_for_API_contract'] = "./openapi.json"
# defaultModelsExpandDepth = -1 => do not display data models
app.app.jinja_env.globals["defaultModelsExpandDepth"] = "-1"
# Workaround to serve media in development server
# Comment for production
@app.route("/media/<image>")
def media_for_dev(image):
return send_from_directory("../media/", image)
# Force the direct encoding of accents in json
app.app.config['JSON_AS_ASCII'] = False
# Remove A-z sorting in json
app.app.config['JSON_SORT_KEYS'] = False
# Authorize cors from all sites
CORS(app.app)
return app
if __name__ == '__main__':
app = main()
app.run(port=8080)