Skip to content

Commit

Permalink
Do not attempt to generate a response schema for form-only requests
Browse files Browse the repository at this point in the history
It would probably fail because Schema objects cannot represent files
  • Loading branch information
axnsan12 committed Dec 15, 2017
1 parent e14c102 commit f6a535e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/drf_yasg/inspectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def get_default_responses(self):
default_schema = self.get_request_serializer()

default_schema = default_schema or ''
if any(is_form_media_type(encoding) for encoding in self.get_consumes()):
default_schema = ''
if default_schema:
if not isinstance(default_schema, openapi.Schema):
default_schema = self.serializer_to_schema(default_schema)
Expand Down
2 changes: 1 addition & 1 deletion testproj/articles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def today(self, request):
return Response(serializer.data)

@swagger_auto_schema(method='get', operation_description="image GET description override")
@swagger_auto_schema(method='post', request_body=serializers.ImageUploadSerializer, responses={200: 'success'})
@swagger_auto_schema(method='post', request_body=serializers.ImageUploadSerializer)
@detail_route(methods=['get', 'post'], parser_classes=(MultiPartParser,))
def image(self, request, slug=None):
"""
Expand Down
6 changes: 2 additions & 4 deletions tests/reference.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ paths:
responses:
'200':
description: ''
schema:
$ref: '#/definitions/Article'
consumes:
- multipart/form-data
tags:
Expand Down Expand Up @@ -221,8 +219,8 @@ paths:
required: true
type: file
responses:
'200':
description: success
'201':
description: ''
consumes:
- multipart/form-data
tags:
Expand Down

2 comments on commit f6a535e

@dkliban
Copy link

@dkliban dkliban commented on f6a535e Sep 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@axnsan12 Did you add this behavior because there was a bug in this area?

I ended up adding a custom inspector to my ViewSet that has the exact behavior that was present before this patch. https://github.com/pulp/pulp/pull/3613/files

@axnsan12
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is leftover cruft from way before #21 was in. It should probably be removed...

Please sign in to comment.