diff --git a/src/drf_yasg/inspectors/field.py b/src/drf_yasg/inspectors/field.py index 87139e4..4879c50 100644 --- a/src/drf_yasg/inspectors/field.py +++ b/src/drf_yasg/inspectors/field.py @@ -597,16 +597,22 @@ class ChoiceFieldInspector(FieldInspector): if model_type: enum_type = model_type.get('type', enum_type) + enum_values = list(field.choices.keys()) if isinstance(field, serializers.MultipleChoiceField): - return SwaggerType( + result = SwaggerType( type=openapi.TYPE_ARRAY, items=ChildSwaggerType( type=enum_type, - enum=list(field.choices.keys()) + enum=enum_values ) ) + if swagger_object_type == openapi.Parameter: + if result['in'] in (openapi.IN_FORM, openapi.IN_QUERY): + result.collection_format = 'multi' + else: + result = SwaggerType(type=enum_type, enum=enum_values) - return SwaggerType(type=enum_type, enum=list(field.choices.keys())) + return result return NotHandled diff --git a/testproj/users/serializers.py b/testproj/users/serializers.py index 8c5dc54..82431a8 100644 --- a/testproj/users/serializers.py +++ b/testproj/users/serializers.py @@ -81,3 +81,4 @@ class UserSerializerrr(serializers.ModelSerializer): class UserListQuerySerializer(serializers.Serializer): username = serializers.CharField(help_text="this field is generated from a query_serializer", required=False) is_staff = serializers.BooleanField(help_text="this one too!", required=False) + styles = serializers.MultipleChoiceField(help_text="and this one is fancy!", choices=('a', 'b', 'c', 'd')) diff --git a/tests/reference.yaml b/tests/reference.yaml index cd73ff5..852bba9 100644 --- a/tests/reference.yaml +++ b/tests/reference.yaml @@ -740,6 +740,19 @@ paths: description: this one too! required: false type: boolean + - name: styles + in: query + description: and this one is fancy! + required: true + type: array + items: + type: string + enum: + - a + - b + - c + - d + collectionFormat: multi responses: '200': description: '' @@ -1159,6 +1172,7 @@ definitions: - fan - fancy - felix + - fennel - fish - flatline - forth @@ -1184,6 +1198,7 @@ definitions: - haskell - haxeml - hexdump + - hlsl - hsail - html - html+cheetah @@ -1450,6 +1465,7 @@ definitions: - xml+php - xml+smarty - xml+velocity + - xorg.conf - xquery - xslt - xtend