Skip to content

Commit

Permalink
Merge 93be2d5 into 3ed9821
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Jun 2, 2018
2 parents 3ed9821 + 93be2d5 commit 1c1e7bc
Show file tree
Hide file tree
Showing 21 changed files with 314 additions and 338 deletions.
85 changes: 85 additions & 0 deletions examples/changelog_090.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""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',
}
}

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()
3 changes: 1 addition & 2 deletions examples/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

app = Flask(__name__)
app.config['SWAGGER'] = {
'title': 'Colors API',
'uiversion': 2
'title': 'Colors API'
}
Swagger(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Using UIVERSION = Swagger UI 3.
Using UIVERSION = Swagger UI 2.
"""

from flask import Flask, jsonify
Expand All @@ -8,8 +8,8 @@

app = Flask(__name__)
app.config['SWAGGER'] = {
'title': 'Colors API Using Swagger UI 3',
'uiversion': 3
'title': 'Colors API Using Swagger UI 2 (old)',
'uiversion': 2
}
Swagger(app)

Expand Down
2 changes: 1 addition & 1 deletion flasgger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

__version__ = '0.8.3'
__version__ = '0.9.0'
__author__ = 'Bruno Rocha'
__email__ = 'rochacbruno@gmail.com'

Expand Down
10 changes: 9 additions & 1 deletion flasgger/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from .utils import get_vendor_extension_fields
from .utils import validate
from .utils import LazyString
from . import __version__

NO_SANITIZER = lambda text: text # noqa
BR_SANITIZER = lambda text: text.replace('\n', '<br/>') if text else text # noqa
Expand Down Expand Up @@ -72,6 +73,13 @@ def get(self):
# calling with ?json returns specs
return jsonify(data)
else: # pragma: no cover
data['flasgger_config'] = self.config
data['json'] = json
data['flasgger_version'] = __version__
data['favicon'] = self.config.get(
'favicon',
url_for('flasgger.static', filename='favicon-32x32.png')
)
return render_template(
'flasgger/index.html',
**data
Expand Down Expand Up @@ -409,7 +417,7 @@ def wrap_view(view):
return view

if self.config.get('swagger_ui', True):
uiversion = self.config.get('uiversion', 2)
uiversion = self.config.get('uiversion', 3)
blueprint = Blueprint(
self.config.get('endpoint', 'flasgger'),
__name__,
Expand Down
95 changes: 0 additions & 95 deletions flasgger/ui3/static/index.html

This file was deleted.

60 changes: 0 additions & 60 deletions flasgger/ui3/static/oauth2-redirect.html

This file was deleted.

71 changes: 38 additions & 33 deletions flasgger/ui3/static/swagger-ui-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion flasgger/ui3/static/swagger-ui-bundle.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 1c1e7bc

Please sign in to comment.