From 00cfa2e8a475944cadbbe6e159c3d90641fb391b Mon Sep 17 00:00:00 2001 From: Phil Krylov Date: Fri, 11 Aug 2017 18:54:47 +0300 Subject: [PATCH] Fixed array member format in form parameters. --- rest_framework_swagger/docgenerator.py | 9 +++++++++ rest_framework_swagger/introspectors.py | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/rest_framework_swagger/docgenerator.py b/rest_framework_swagger/docgenerator.py index f83174b0..3753d9cd 100644 --- a/rest_framework_swagger/docgenerator.py +++ b/rest_framework_swagger/docgenerator.py @@ -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): @@ -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 diff --git a/rest_framework_swagger/introspectors.py b/rest_framework_swagger/introspectors.py index fb84598a..05f2cbf9 100644 --- a/rest_framework_swagger/introspectors.py +++ b/rest_framework_swagger/introspectors.py @@ -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): @@ -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