| 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 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
'hide_top_bar': True, |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
'footer_text': '<b>Hello World </b><script>alert("Hello World!")</script>', |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
'top_text': '<b><span class="top_text">Welcome to my api </span></b>', |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
'head_text': '<style>.top_text{color: red;}</style>', |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
'doc_expansion': "list", |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
'ui_params': { |
| 52 |
'apisSorter': 'alpha', |
| 53 |
'operationsSorter': 'alpha', |
| 54 |
}, |
| 55 |
|
| 56 |
|
| 57 |
|
| 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() |