noirbizarre / flask-restplus

Fully featured framework for fast, easy and documented API development with Flask
http://flask-restplus.readthedocs.org
Other
2.73k stars 507 forks source link

@api.expect() decorator with "validate=False" doesn't work #609

Closed dstrigl closed 5 years ago

dstrigl commented 5 years ago

Corresponding to the documentation at https://flask-restplus.readthedocs.io/en/stable/swagger.html the following sample

api = Api(app, validate=True)
resource_fields = api.model('Resource', {
    'name': fields.String,
})
@api.route('/my-resource/<id>')
class MyResource(Resource):
    # Payload validation disabled
    @api.expect(resource_fields, validate=False)
    def post(self):
        pass`

doesn't work as expected:

The payload validation for the POST method is active, although the decorator @api.expect(...) is called with validate=False.

After a short look in the source code I would say that both, the function expect in namespace.py and the unit test test_validation_true_on_constructor_with_override in test_payload.py is not really correct.

xshibux commented 5 years ago

I'm having the same issue. Can someone help?

dstrigl commented 5 years ago

https://github.com/noirbizarre/flask-restplus/pull/610

SteadBytes commented 5 years ago

You are correct, the intended behaviour is for validation on all resources to default to the validation set on the Api constructor but can be overridden on a per resources basis by passing the validate kwarg to api.expect as shown in your demo @dstrigl . I am going to take a look at your PR now :+1:

SteadBytes commented 5 years ago

@dstrigl I have left a comment on the PR :smile:

ibejohn818 commented 5 years ago

Since this hasn't been merged into an upstream release there is another work around with the current release. You can use the "doc" decorator to get the same "payload" documentation and disable validation IE: @api.doc(body=my_model, validate=False)