Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Stable/0.3.x: Fix array member format in form params and model properties #690

Open
wants to merge 1 commit into
base: stable/0.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rest_framework_swagger/docgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ def _get_serializer_fields(self, serializer):
# if data_type in BaseMethodIntrospector.PRIMITIVES:
# data_format = BaseMethodIntrospector.PRIMITIVES.get(data_type)[0]

items_type = None
if data_type == 'array':
items_type, items_format = get_data_type(field.child)

choices = []
if data_type in BaseMethodIntrospector.ENUMS:
if isinstance(field.choices, list):
Expand Down Expand Up @@ -407,6 +411,11 @@ def _get_serializer_fields(self, serializer):
elif data_type in BaseMethodIntrospector.PRIMITIVES:
f['items'] = {'type': data_type}

if items_type:
f['items'] = {'type': items_type}
if items_format != items_type:
f['items']['format'] = items_format

# memorize discovered field
data['fields'][name] = f

Expand Down
10 changes: 10 additions & 0 deletions rest_framework_swagger/introspectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ def build_form_parameters(self):
# if data_type in self.PRIMITIVES:
# data_format = self.PRIMITIVES.get(data_type)[0]

items_type = None
if data_type == 'array':
items_type, items_format = get_data_type(field.child)

choices = []
if data_type in BaseMethodIntrospector.ENUMS:
if isinstance(field.choices, list):
Expand Down Expand Up @@ -495,6 +499,12 @@ def build_form_parameters(self):
if choices:
f['enum'] = choices

if items_type:
items = {'type': items_type}
if items_format != items_type:
items['format'] = items_format
f['items'] = items

data.append(f)

return data
Expand Down