Use collectionFormat=multi for MultiChoiceField in query and formData

Fixes #257.
This commit is contained in:
Cristi Vîjdea
2018-11-29 01:38:32 +02:00
parent 9f60dc191a
commit 708e70a526
3 changed files with 26 additions and 3 deletions
+9 -3
View File
@@ -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