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

Cannot manually represent a Response without setting a schema? #66

Closed
insertjokehere opened this issue Feb 22, 2018 · 1 comment
Closed
Assignees
Labels
bug Bug report/fix
Milestone

Comments

@insertjokehere
Copy link

Not sure if this is a bug, or if I'm just not reading the docs correctly:

I have a view that returns a '204 No Content' status, with a header that returns some relevant information, and no response body. I want to correctly represent this in my API documentation, so I'm doing something like this:

class MyView(APIView):
    @swagger_auto_schema(
        responses={
            "204": openapi.Response(
                description="Your request was accepted, perform status queries using the value of the X-Query-ID header for updates",
                 headers={
                     "X-Query-ID": {
                         "description": "The ID of the accepted query",
                         "type": openapi.TYPE_STRING
                     }
                 }
             )
         }
    )
    def post(self, request, ...):

However this fails with the following trace:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/drf_yasg/openapi.py", line 99, in __getattr__
    return self[make_swagger_name(item)]
KeyError: 'schema'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 494, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 454, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 491, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/drf_yasg/views.py", line 88, in get
    schema = generator.get_schema(request, self.public)
  File "/usr/local/lib/python3.6/site-packages/drf_yasg/generators.py", line 203, in get_schema
    paths, prefix = self.get_paths(endpoints, components, request, public)
  File "/usr/local/lib/python3.6/site-packages/drf_yasg/generators.py", line 317, in get_paths
    operations[method.lower()] = self.get_operation(view, path, prefix, method, components, request)
  File "/usr/local/lib/python3.6/site-packages/drf_yasg/generators.py", line 357, in get_operation
    operation = view_inspector.get_operation(operation_keys)
  File "/usr/local/lib/python3.6/site-packages/drf_yasg/inspectors/view.py", line 38, in get_operation
    responses = self.get_responses()
  File "/usr/local/lib/python3.6/site-packages/drf_yasg/inspectors/view.py", line 161, in get_responses
    responses=self.get_response_schemas(response_serializers)
  File "/src/lib/ucee-django-utils/ucee_django_utils/schema.py", line 25, in get_response_schemas
    resp_schemas = super().get_response_schemas(response_serializers)
  File "/usr/local/lib/python3.6/site-packages/drf_yasg/inspectors/view.py", line 224, in get_response_schemas
    if not isinstance(response.schema, openapi.Schema.OR_REF):
  File "/usr/local/lib/python3.6/site-packages/drf_yasg/openapi.py", line 102, in __getattr__
    raise AttributeError("object of class " + type(self).__name__ + " has no attribute " + item)
AttributeError: object of class Response has no attribute schema
[22/Feb/2018 13:45:45] "GET /_internal/auth/schema HTTP/1.0" 500 17194

It works if I set the schema kwarg on the Response (either with a serializer or a manually created Schema instance; setting it to no_body doesn't work). As far as I can tell I should be able to specify a Response without a Schema (I can if I set the value of the responses dict to a string)?

@axnsan12 axnsan12 added the bug Bug report/fix label Feb 22, 2018
@axnsan12 axnsan12 self-assigned this Feb 22, 2018
@axnsan12 axnsan12 added this to the 1.4.2 milestone Feb 22, 2018
@axnsan12
Copy link
Owner

Yep. This looks like an oversight. Will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report/fix
Projects
None yet
Development

No branches or pull requests

2 participants