-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" | ||
The simple example using declared definitions, and external static js/css. | ||
""" | ||
|
||
from flask import Flask, jsonify | ||
|
||
from flasgger import Swagger | ||
|
||
app = Flask(__name__) | ||
app.config['SWAGGER'] = { | ||
'title': 'OA3 Callbacks' | ||
} | ||
swagger_config = Swagger.DEFAULT_CONFIG | ||
swagger_config['swagger_ui_bundle_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js' | ||
swagger_config['swagger_ui_standalone_preset_js'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js' | ||
swagger_config['jquery_js'] = '//unpkg.com/jquery@2.2.4/dist/jquery.min.js' | ||
swagger_config['swagger_ui_css'] = '//unpkg.com/swagger-ui-dist@3/swagger-ui.css' | ||
Swagger(app, config=swagger_config) | ||
|
||
@app.route('/run_callback/', methods=['POST']) | ||
def run_callback(): | ||
"""Example endpoint that specifies OA3 callbacks | ||
This is using docstring for specifications | ||
--- | ||
tags: | ||
- callbacks | ||
requestBody: | ||
description: Test | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
callback_url: | ||
type: string | ||
format: uri | ||
description: Callback URL for request | ||
callbacks: | ||
onSomeEvent: | ||
'{$request.body.callback_url}': | ||
post: | ||
requestBody: | ||
description: status payload | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
status: | ||
type: string | ||
""" | ||
|
||
return jsonify({'result': 'ok'}) | ||
|
||
|
||
def test_swag(client, specs_data): | ||
""" | ||
This test is runs automatically in Travis CI | ||
:param client: Flask app test client | ||
:param specs_data: {'url': {swag_specs}} for every spec in app | ||
""" | ||
for url, spec in specs_data.items(): | ||
assert 'callbacks' in spec['paths']['/run_callback/']['post'] | ||
assert 'onSomeEvent' in spec['paths']['/run_callback/']['post']['callbacks'] | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters