@@ -46,6 +46,7 @@ Swagger(app)
46
46
@app.route (' /colors/<palette>/' )
47
47
def colors (palette ):
48
48
""" Example endpoint returning a list of colors by palette
49
+ This is using docstrings for specifications.
49
50
---
50
51
parameters:
51
52
- name: palette
@@ -144,11 +145,9 @@ def colors(palette):
144
145
...
145
146
` ` `
146
147
147
- If you do not want to use the decorator you can use the docsting shortcut.
148
+ If you do not want to use the decorator you can use the docsting ` file:` shortcut.
148
149
149
150
` ` ` python
150
- from flasgger import swag_from
151
-
152
151
@app.route('/colors/<palette>/')
153
152
def colors(palette):
154
153
"""
@@ -160,7 +159,7 @@ def colors(palette):
160
159
161
160
# # Using dictionaries as raw specs
162
161
163
- Create a Python dictionary with as:
162
+ Create a Python dictionary as :
164
163
165
164
` ` ` python
166
165
specs_dict = {
@@ -219,7 +218,7 @@ Now take the same function and use the dict in the place of YAML file.
219
218
@swag_from(specs_dict)
220
219
def colors(palette):
221
220
"""Example endpoint returning a list of colors by palette
222
- In this example the specification is taken from external YAML file
221
+ In this example the specification is taken from specs_dict
223
222
"""
224
223
...
225
224
` ` `
@@ -236,12 +235,10 @@ from flasgger import Swagger, SwaggerView, Schema, fields
236
235
class Color(Schema):
237
236
name = fields.Str()
238
237
239
-
240
238
class Palette(Schema):
241
239
pallete_name = fields.Str()
242
240
colors = fields.Nested(Color, many=True)
243
241
244
-
245
242
class PaletteView(SwaggerView):
246
243
parameters = [
247
244
{
@@ -275,7 +272,6 @@ class PaletteView(SwaggerView):
275
272
result = {palette: all_colors.get(palette)}
276
273
return jsonify(result)
277
274
278
-
279
275
app = Flask(__name__)
280
276
Swagger(app)
281
277
@@ -313,7 +309,11 @@ def fromfile_decorated(username=None):
313
309
return jsonify({'username': username})
314
310
` ` `
315
311
316
- # Use the same yaml file to validate your API data
312
+ And the same can be achieved with multiple methods in a `MethodView` or `SwaggerView` by
313
+ registering the `url_rule` many times. Take a look at `examples/example_app`
314
+
315
+
316
+ # Use the same data to validate your API POST body.
317
317
318
318
` ` ` python
319
319
from flasgger import swag_from, validate
@@ -336,6 +336,9 @@ def post():
336
336
# also returns the validation message.
337
337
` ` `
338
338
339
+ It is also possible to define `validation=True` in `SwaggerView` and also use
340
+ ` specs_dict` for validation.
341
+
339
342
Take a look at `examples/validation.py` for more information.
340
343
341
344
All validation options can be found at http://json-schema.org/latest/json-schema-validation.html
@@ -382,7 +385,7 @@ Swagger(app)
382
385
383
386
```
384
387
385
- # Starting with defauts .
388
+ # Initializing Flasgger with default data .
386
389
387
390
You can start your Swagger spec with any default data providing a template:
388
391
0 commit comments