Skip to content

Commit 24adcbc

Browse files
committed
[docs] Fix incorrect input/output model examples.
This example has 2 main issues: 1. The model assigned to the fields variable shadows the flask_restx.fields module, causing an AttributeError 2. The @api.model usage is simply incorrect, it is not intended to be used as a class decorator on custom field implementations. The corrections made here show what I *assume* the original author intended to show. #117 (comment) Signed-off-by: Ben Steadman <[email protected]>
1 parent 50c54f0 commit 24adcbc

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

doc/swagger.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,13 @@ For ``POST`` and ``PUT`` methods, use the ``body`` keyword argument to specify t
536536

537537
.. code-block:: python
538538
539-
fields = api.model('MyModel', {
539+
my_model = api.model('MyModel', {
540540
'name': fields.String(description='The name', required=True),
541541
'type': fields.String(description='The object type', enum=['A', 'B']),
542542
'age': fields.Integer(min=0),
543543
})
544544
545545
546-
@api.model(fields={'name': fields.String, 'age': fields.Integer})
547546
class Person(fields.Raw):
548547
def format(self, value):
549548
return {'name': value.name, 'age': value.age}
@@ -552,11 +551,11 @@ For ``POST`` and ``PUT`` methods, use the ``body`` keyword argument to specify t
552551
@api.route('/my-resource/<id>', endpoint='my-resource')
553552
@api.doc(params={'id': 'An ID'})
554553
class MyResource(Resource):
555-
@api.doc(model=fields)
554+
@api.doc(model=my_model)
556555
def get(self, id):
557556
return {}
558557
559-
@api.doc(model='MyModel', body=Person)
558+
@api.doc(model=my_model, body=Person)
560559
def post(self, id):
561560
return {}
562561

0 commit comments

Comments
 (0)