forked from flasgger/flasgger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangelog_090.py
91 lines (75 loc) · 2.97 KB
/
changelog_090.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""0.9.0 News and Changes
- Updated Swagger UI 3.x
- uiversion now defaults to 3
- 'hide_top_bar' config option to remove the green top bar
- 'fotter_text' added to customize the footer text (allows html and <script>)
- templates/flasgger/footer.html added and can be replaced to customization
this footer.html is the right place for custom <script>
- 'top_text' added to customize the header text (allows html)
- templates/flasgger/top.html added and can be replaced to customization
- 'head_text' added to customize the <head> (allows html)
- templates/flasgger/head.html added and can be replaced to customization
- added 'doc_expansion' config to control the collapse
- added 'ui_params' to allow override of any swagger.ui values
"""
from flask import Flask, request
from flasgger import Swagger
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['SWAGGER'] = {
'title': 'MyAPI',
# UI version 3 is now the default
# 'uiversion': '3',
# This setup hides the green top bar
'hide_top_bar': True,
# this text is rendered in the footer
# (optionally you can replace flasgger/footer.html template)
'footer_text': '<b>Hello World </b><script>alert("Hello World!")</script>',
# this text is rendered in the header
# (optionally you can replace flasgger/header.html template)
'top_text': '<b><span class="top_text">Welcome to my api </span></b>',
# this text is rendered in the <head>
# (optionally you can replace flasgger/head.html template)
'head_text': '<style>.top_text{color: red;}</style>',
# Control the collapse of each tag, '"none"' means all tags default closed
# "none" - It'll Hide everything.
# "list"- It'll expand/List all the operations only. (default)
# "full" - It'll expand everything(Full expand as the name says).
'doc_expansion': "list",
# Allows overriding any of the uiparams
# This is useful to override other stuff not provided by the above aliases
'ui_params': {
'apisSorter': 'alpha',
'operationsSorter': 'alpha',
},
# Allows overriding any of the uiparams with Javascript expressions
# This is useful to override other stuff not provided by the above aliases which cannot be serialized to a JSON string
'ui_params_text': '''{
"operationsSorter" : (a, b) => a.get("path").localeCompare(b.get("path"))
}'''
}
Swagger(app)
@app.route('/', methods=['GET', 'POST'])
def main_route():
"""
Test Endpoint
---
tags:
- Test
parameters:
- name: data
in: formData
required: True
type: string
description: data to send
responses:
200:
description: data received successfully
404:
description: data not found in request form
"""
if 'data' not in request.form.keys():
return 'data not found in request form', 404
return 'data received: ' + str(request.form['data'])
if __name__ == '__main__':
app.run()