flask-restplus-server-example
flask-restplus-server-example copied to clipboard
Restrict responses with only documented types (@api.response(code=...))
#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).
May I ask you to provide a little details or just explain what do you want? :)
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).