Debian Codegraph @

examples/changelog_090.py

raw symbols SCIP
1 """0.9.0 News and Changes
2
3 - Updated Swagger UI 3.x
4 - uiversion now defaults to 3
5 - 'hide_top_bar' config option to remove the green top bar
6 - 'fotter_text' added to customize the footer text (allows html and <script>)
7 - templates/flasgger/footer.html added and can be replaced to customization
8 this footer.html is the right place for custom <script>
9 - 'top_text' added to customize the header text (allows html)
10 - templates/flasgger/top.html added and can be replaced to customization
11 - 'head_text' added to customize the <head> (allows html)
12 - templates/flasgger/head.html added and can be replaced to customization
13 - added 'doc_expansion' config to control the collapse
14 - added 'ui_params' to allow override of any swagger.ui values
15 """
16
17 from flask import Flask, request
18 from flasgger import Swagger
19
20 app = Flask(__name__)
21 app.config['TEMPLATES_AUTO_RELOAD'] = True
22 app.config['SWAGGER'] = {
23 'title': 'MyAPI',
24
25 # UI version 3 is now the default
26 # 'uiversion': '3',
27
28 # This setup hides the green top bar
29 'hide_top_bar': True,
30
31 # this text is rendered in the footer
32 # (optionally you can replace flasgger/footer.html template)
33 'footer_text': '<b>Hello World </b><script>alert("Hello World!")</script>',
34
35 # this text is rendered in the header
36 # (optionally you can replace flasgger/header.html template)
37 'top_text': '<b><span class="top_text">Welcome to my api </span></b>',
38
39 # this text is rendered in the <head>
40 # (optionally you can replace flasgger/head.html template)
41 'head_text': '<style>.top_text{color: red;}</style>',
42
43 # Control the collapse of each tag, '"none"' means all tags default closed
44 # "none" - It'll Hide everything.
45 # "list"- It'll expand/List all the operations only. (default)
46 # "full" - It'll expand everything(Full expand as the name says).
47 'doc_expansion': "list",
48
49 # Allows overriding any of the uiparams
50 # This is useful to override other stuff not provided by the above aliases
51 'ui_params': {
52 'apisSorter': 'alpha',
53 'operationsSorter': 'alpha',
54 },
55
56 # Allows overriding any of the uiparams with Javascript expressions
57 # This is useful to override other stuff not provided by the above aliases which cannot be serialized to a JSON string
58 'ui_params_text': '''{
59 "operationsSorter" : (a, b) => a.get("path").localeCompare(b.get("path"))
60 }'''
61 }
62
63 Swagger(app)
64
65
66 @app.route('/', methods=['GET', 'POST'])
67 def main_route():
68 """
69 Test Endpoint
70 ---
71 tags:
72 - Test
73 parameters:
74 - name: data
75 in: formData
76 required: True
77 type: string
78 description: data to send
79 responses:
80 200:
81 description: data received successfully
82 404:
83 description: data not found in request form
84 """
85 if 'data' not in request.form.keys():
86 return 'data not found in request form', 404
87 return 'data received: ' + str(request.form['data'])
88
89
90 if __name__ == '__main__':
91 app.run()