Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to generate the Response Body API documentation without using Response decorator? #56

Open
zain2323 opened this issue Aug 26, 2022 · 3 comments
Labels
question Further information is requested

Comments

@zain2323
Copy link

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?

@miguelgrinberg
Copy link
Owner

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.

@miguelgrinberg miguelgrinberg added the question Further information is requested label Aug 26, 2022
@anilravuri
Copy link

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.

Any thoughts on this?

@miguelgrinberg
Copy link
Owner

Handling special documentation needs in the process_apispec handler is what I have envisioned, so that seems like a good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants