Fix lint errors

This commit is contained in:
Cristi Vîjdea
2020-02-17 03:06:37 +02:00
parent a872eb66d6
commit 17da098940
3 changed files with 12 additions and 9 deletions
+2 -2
View File
@@ -1,3 +1,5 @@
from six import binary_type, raise_from, text_type
import copy
import json
import logging
@@ -6,8 +8,6 @@ from collections import OrderedDict
from coreapi.compat import force_bytes
from ruamel import yaml
from six import binary_type, raise_from, text_type
from . import openapi
from .errors import SwaggerValidationError
+8 -6
View File
@@ -375,14 +375,16 @@ 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**.
# Because swagger Parameter objects don't support complex data types (nested objects, arrays),
# we can't use those unless we are sure the view *only* accepts form data
# This means that a view won't support file upload in swagger unless it explicitly
# sets its parser classes to include only form parsers
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
# If the form accepts both form data and another type, like json (which is the default config),
# we will render its input as a Schema and thus it file parameters will be read-only
return non_form_media_types
def get_produces(renderer_classes):