Fix lint errors

master
Cristi Vîjdea 2020-02-17 03:06:37 +02:00
parent a872eb66d6
commit 17da098940
3 changed files with 12 additions and 9 deletions

View File

@ -1,3 +1,5 @@
from six import binary_type, raise_from, text_type
import copy import copy
import json import json
import logging import logging
@ -6,8 +8,6 @@ from collections import OrderedDict
from coreapi.compat import force_bytes from coreapi.compat import force_bytes
from ruamel import yaml from ruamel import yaml
from six import binary_type, raise_from, text_type
from . import openapi from . import openapi
from .errors import SwaggerValidationError from .errors import SwaggerValidationError

View File

@ -375,13 +375,15 @@ def get_consumes(parser_classes):
parser_classes = [pc for pc in parser_classes if not issubclass(pc, FileUploadParser)] parser_classes = [pc for pc in parser_classes if not issubclass(pc, FileUploadParser)]
media_types = [parser.media_type for parser in parser_classes or []] 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)] 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, # Because swagger Parameter objects don't support complex data types (nested objects, arrays),
# we must be sure to have explicit form media types **only**. # 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: if len(non_form_media_types) == 0:
return media_types 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... # If the form accepts both form data and another type, like json (which is the default config),
else: # we will render its input as a Schema and thus it file parameters will be read-only
return non_form_media_types return non_form_media_types

View File

@ -7,11 +7,11 @@ from django.conf.urls import url
from django.contrib.postgres import fields as postgres_fields from django.contrib.postgres import fields as postgres_fields
from django.db import models from django.db import models
from django.utils.inspect import get_func_args from django.utils.inspect import get_func_args
from django_fake_model import models as fake_models
from rest_framework import routers, serializers, viewsets from rest_framework import routers, serializers, viewsets
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from rest_framework.response import Response from rest_framework.response import Response
from django_fake_model import models as fake_models
from drf_yasg import codecs, openapi from drf_yasg import codecs, openapi
from drf_yasg.codecs import yaml_sane_load from drf_yasg.codecs import yaml_sane_load
from drf_yasg.errors import SwaggerGenerationError from drf_yasg.errors import SwaggerGenerationError
@ -347,6 +347,7 @@ EXPECTED_DESCRIPTION = """\
You can log in using the pre-existing `admin` user with password `passwordadmin`. You can log in using the pre-existing `admin` user with password `passwordadmin`.
""" """
def test_multiline_strings(call_generate_swagger): def test_multiline_strings(call_generate_swagger):
output = call_generate_swagger(format='yaml') output = call_generate_swagger(format='yaml')
print("|\n|".join(output.splitlines()[:20])) print("|\n|".join(output.splitlines()[:20]))