forked from flasgger/flasgger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbacks.py
69 lines (57 loc) · 1.65 KB
/
callbacks.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
"""
The simple example using OpenAPI 3.0 callbacks
"""
from flask import Flask, jsonify
from flasgger import Swagger
app = Flask(__name__)
app.config['SWAGGER'] = {
'title': 'OA3 Callbacks',
'openapi': '3.0.2'
}
Swagger(app)
@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 'openapi' in spec
assert spec['openapi'] == '3.0.2'
assert 'callbacks' in spec['paths']['/run_callback/']['post']
assert 'onSomeEvent' in \
spec['paths']['/run_callback/']['post']['callbacks']
if __name__ == "__main__":
app.run(debug=True)