You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to document the Response body in the API documentation of the view function but I can not use the Response decorator since the response is already parsed and using the Response decorator raises the following exception. RuntimeError: The @response decorator cannot handle Response objects.
To solve the issue, I modified the Response decorator, and instead of raising an Exception when a Response object is encountered, I returned the object.
@wraps(f)
def _response(*args, **kwargs):
rv = f(*args, **kwargs)
if isinstance(rv, Response): # pragma: no cover
#raise RuntimeError(
#'The @response decorator cannot handle Response objects.')
return rv # Returning the response object instead of raising an Exception
This works fine now but is there any better way to do this?
The text was updated successfully, but these errors were encountered:
Using a modified decorator is the easiest way. This isn't a use case that I think should be handled in this library, as it makes it easy for the documentation and the actual response to be out of sync. The idea of the response decorator is that it ensures the documentation and the code always are set to the same thing.
I had a similar use case where I wanted to document streaming file responses. I was able to get it to work by not using the @response decorator and explicitly creating the schema using @apifairy.process_apispec.
I want to document the Response body in the API documentation of the view function but I can not use the Response decorator since the response is already parsed and using the Response decorator raises the following exception.
RuntimeError: The @response decorator cannot handle Response objects.
To solve the issue, I modified the Response decorator, and instead of raising an Exception when a Response object is encountered, I returned the object.
This works fine now but is there any better way to do this?
The text was updated successfully, but these errors were encountered: