diff --git a/src/drf_yasg/inspectors/view.py b/src/drf_yasg/inspectors/view.py index a025dee..821328c 100644 --- a/src/drf_yasg/inspectors/view.py +++ b/src/drf_yasg/inspectors/view.py @@ -230,6 +230,8 @@ class SwaggerAutoSchema(ViewInspector): response = openapi.Response( description=serializer ) + elif not serializer: + continue elif isinstance(serializer, openapi.Response): response = serializer if hasattr(response, 'schema') and not isinstance(response.schema, openapi.Schema.OR_REF): diff --git a/src/drf_yasg/utils.py b/src/drf_yasg/utils.py index d3d17d1..a457388 100644 --- a/src/drf_yasg/utils.py +++ b/src/drf_yasg/utils.py @@ -76,6 +76,8 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo * if a plain string is given as value, a :class:`.Response` with no body and that string as its description will be generated + * if ``None`` is given as a value, the response is ignored; this is mainly useful for disabling default + 2xx responses, i.e. ``responses={200: None, 302: 'something'}`` * if a :class:`.Schema`, :class:`.SchemaRef` is given, a :class:`.Response` with the schema as its body and an empty description will be generated * a ``Serializer`` class or instance will be converted into a :class:`.Schema` and treated as above diff --git a/testproj/todo/views.py b/testproj/todo/views.py index f778d70..621b9a1 100644 --- a/testproj/todo/views.py +++ b/testproj/todo/views.py @@ -57,7 +57,7 @@ class TodoRecursiveView(viewsets.ModelViewSet): def create(self, request, *args, **kwargs): return super(TodoRecursiveView, self).create(request, *args, **kwargs) - @swagger_auto_schema(responses={200: TodoRecursiveSerializer}) + @swagger_auto_schema(responses={200: None, 302: 'Redirect somewhere'}) def retrieve(self, request, *args, **kwargs): return super(TodoRecursiveView, self).retrieve(request, *args, **kwargs) diff --git a/tests/reference.yaml b/tests/reference.yaml index 0277c6f..4e5a570 100644 --- a/tests/reference.yaml +++ b/tests/reference.yaml @@ -560,10 +560,8 @@ paths: description: '' parameters: [] responses: - '200': - description: '' - schema: - $ref: '#/definitions/TodoRecursive' + '302': + description: Redirect somewhere tags: - todo put: