Ignore None when passed in as response override

Closes #148
openapi3
Cristi Vîjdea 2018-06-29 23:13:36 +03:00
parent 544d72db0a
commit 9fa4765121
4 changed files with 7 additions and 5 deletions

View File

@ -230,6 +230,8 @@ class SwaggerAutoSchema(ViewInspector):
response = openapi.Response( response = openapi.Response(
description=serializer description=serializer
) )
elif not serializer:
continue
elif isinstance(serializer, openapi.Response): elif isinstance(serializer, openapi.Response):
response = serializer response = serializer
if hasattr(response, 'schema') and not isinstance(response.schema, openapi.Schema.OR_REF): if hasattr(response, 'schema') and not isinstance(response.schema, openapi.Schema.OR_REF):

View File

@ -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 * if a plain string is given as value, a :class:`.Response` with no body and that string as its description
will be generated 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 * if a :class:`.Schema`, :class:`.SchemaRef` is given, a :class:`.Response` with the schema as its body and
an empty description will be generated an empty description will be generated
* a ``Serializer`` class or instance will be converted into a :class:`.Schema` and treated as above * a ``Serializer`` class or instance will be converted into a :class:`.Schema` and treated as above

View File

@ -57,7 +57,7 @@ class TodoRecursiveView(viewsets.ModelViewSet):
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
return super(TodoRecursiveView, self).create(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): def retrieve(self, request, *args, **kwargs):
return super(TodoRecursiveView, self).retrieve(request, *args, **kwargs) return super(TodoRecursiveView, self).retrieve(request, *args, **kwargs)

View File

@ -560,10 +560,8 @@ paths:
description: '' description: ''
parameters: [] parameters: []
responses: responses:
'200': '302':
description: '' description: Redirect somewhere
schema:
$ref: '#/definitions/TodoRecursive'
tags: tags:
- todo - todo
put: put: