Skip to content

Commit

Permalink
Add special exclusion for FileUploadParser
Browse files Browse the repository at this point in the history
Fixes #288
  • Loading branch information
axnsan12 committed Mar 3, 2019
1 parent f348084 commit 340a603
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/drf_yasg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils.encoding import force_text
from rest_framework import serializers, status
from rest_framework.mixins import DestroyModelMixin, RetrieveModelMixin, UpdateModelMixin
from rest_framework.parsers import FileUploadParser
from rest_framework.request import is_form_media_type
from rest_framework.settings import api_settings as rest_framework_settings
from rest_framework.utils import encoders, json
Expand Down Expand Up @@ -366,6 +367,7 @@ def get_consumes(parser_classes):
:rtype: list[str]
"""
parser_classes = get_object_classes(parser_classes)
parser_classes = [pc for pc in parser_classes if not issubclass(pc, FileUploadParser)]
media_types = [parser.media_type for parser in parser_classes or []]
non_form_media_types = [encoding for encoding in media_types if not is_form_media_type(encoding)]
if len(non_form_media_types) == 0:
Expand Down
4 changes: 2 additions & 2 deletions testproj/articles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# noinspection PyDeprecation
from rest_framework.filters import OrderingFilter
from rest_framework.pagination import LimitOffsetPagination
from rest_framework.parsers import MultiPartParser
from rest_framework.parsers import MultiPartParser, FileUploadParser
from rest_framework.response import Response

from articles import serializers
Expand Down Expand Up @@ -118,7 +118,7 @@ def today(self, request):
type=openapi.TYPE_INTEGER,
description="this should not crash (form parameter on DELETE method)"
)])
@detail_route(methods=['get', 'post', 'delete'], parser_classes=(MultiPartParser,))
@detail_route(methods=['get', 'post', 'delete'], parser_classes=(MultiPartParser, FileUploadParser))
def image(self, request, slug=None):
"""
image method docstring
Expand Down
4 changes: 2 additions & 2 deletions testproj/snippets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from djangorestframework_camel_case.render import CamelCaseJSONRenderer
from inflection import camelize
from rest_framework import generics, status
from rest_framework.parsers import FormParser
from rest_framework.parsers import FormParser, FileUploadParser

from drf_yasg import openapi
from drf_yasg.inspectors import SwaggerAutoSchema
Expand All @@ -22,7 +22,7 @@ class SnippetList(generics.ListCreateAPIView):
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer

parser_classes = (FormParser, CamelCaseJSONParser,)
parser_classes = (FormParser, CamelCaseJSONParser, FileUploadParser)
renderer_classes = (CamelCaseJSONRenderer,)
swagger_schema = CamelCaseOperationIDAutoSchema

Expand Down

0 comments on commit 340a603

Please sign in to comment.