Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
axnsan12 committed Feb 17, 2020
1 parent a872eb6 commit 17da098
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/drf_yasg/codecs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from six import binary_type, raise_from, text_type

import copy
import json
import logging
Expand All @@ -6,8 +8,6 @@
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

Expand Down
14 changes: 8 additions & 6 deletions src/drf_yasg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_schema_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from django.contrib.postgres import fields as postgres_fields
from django.db import models
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.decorators import api_view
from rest_framework.response import Response

from django_fake_model import models as fake_models
from drf_yasg import codecs, openapi
from drf_yasg.codecs import yaml_sane_load
from drf_yasg.errors import SwaggerGenerationError
Expand Down Expand Up @@ -347,6 +347,7 @@ def retrieve(self, request, pk=None):
You can log in using the pre-existing `admin` user with password `passwordadmin`.
"""


def test_multiline_strings(call_generate_swagger):
output = call_generate_swagger(format='yaml')
print("|\n|".join(output.splitlines()[:20]))
Expand Down

0 comments on commit 17da098

Please sign in to comment.