flask-restplus-server-example icon indicating copy to clipboard operation
flask-restplus-server-example copied to clipboard

Restrict responses with only documented types (@api.response(code=...))

Open frol opened this issue 7 years ago • 2 comments

#26 showed that there might be a situation when all tests pass, the response is expected, but it was not explicitly covered with @api.response() decorator. I think we will need to override Api.output from flask_restplus/api.py (note, there is already customization on Api class in flask_restplus_patched, so you can just add this patch there), so we can check what responses are defined on the resource, and the current response is expected (don't forget about special care around HTTP/500 internal error, this can happen anywhere and shouldn't be shadowed).

frol avatar Sep 23 '16 11:09 frol

May I ask you to provide a little details or just explain what do you want? :)

khorolets avatar Sep 26 '16 17:09 khorolets

Actually, I don't think we need to address this now.

The point of the issue is that I wanted to make sure that all possible responses are documented in Swagger and if it is not, I wanted to raise an exception (only in the Debug mode). Since you cannot inspect the code for all possible return values, I thought to make a check for what is going to be returned somewhere and check if it was documented and then tests would fail even if a resource returns a correct response.

Example, we had DELETE handlers, which returned HTTP/200, and tests passed, but HTTP/200 was not documented in the Swagger UI (nobody cared about it). I want so this won't ever repeat again, if resource returns some data with HTTP/200 and it is not documented, some sort of exception should be raised instead of silently getting response out (even if it is completely legitimate and expected).

frol avatar Sep 26 '16 17:09 frol