Skip to content

Commit

Permalink
add comments on why we returns non form media types by default (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
ychab authored and axnsan12 committed Nov 14, 2019
1 parent 5c25ecd commit b700191
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/drf_yasg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,12 @@ def get_consumes(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)]
# Because some data to parse could be nested array and are not supported by form media type like multipart/form-data,
# we must be sure to have explicit form media types **only**.
if len(non_form_media_types) == 0:
return media_types
# Otherwise, enforce a media type like application/json to be able to parse nested array, but it won't be able to
# support file upload...
else:
return non_form_media_types

Expand Down

0 comments on commit b700191

Please sign in to comment.