Flask gives developers a lot of leeway when it comes view function return values (flask docs.) Flask-Restful did not play well with the particular structure pre 0.8.7, flask-apispec's decorators were using.
Pre 0.8.7 flask-apispec's decorators return a tuple with the first value being a Response object, and optionally a second and third value for the status_code and headers. See point in time here.. In https://github.com/jmcarp/flask-apispec/pull/168 we attempted to fix this by returning a tuple containing only a response object (neglecting to update the headers.)
In this PR, I try and unpack the view function's return value in a safer way (acknowledging the possibility of someone wanting to return a tuple with (response, headers)). Then letting marshal_result just worry about marshaling, and using flask's make_response to return a Response object with updated status code and headers.
Fixes 🤞
"Version 0.8.7 regression" https://github.com/jmcarp/flask-apispec/issues/181 @decaz
Caused by
"Fix serialization problem with return codes when used with flask-restful" https://github.com/jmcarp/flask-apispec/pull/168 @AdamLeyshon
What?
Flask gives developers a lot of leeway when it comes view function return values (flask docs.) Flask-Restful did not play well with the particular structure pre 0.8.7, flask-apispec's decorators were using.
Pre 0.8.7 flask-apispec's decorators return a tuple with the first value being a Response object, and optionally a second and third value for the status_code and headers. See point in time here.. In https://github.com/jmcarp/flask-apispec/pull/168 we attempted to fix this by returning a tuple containing only a response object (neglecting to update the headers.)
In this PR, I try and unpack the view function's return value in a safer way (acknowledging the possibility of someone wanting to return a tuple with
(response, headers)
). Then lettingmarshal_result
just worry about marshaling, and using flask'smake_response
to return a Response object with updated status code and headers.