From 6a365e8737772abc28b2ea9618b2e1e1ec5fe673 Mon Sep 17 00:00:00 2001 From: Angel Velasquez Date: Mon, 17 Oct 2016 17:52:23 -0300 Subject: [PATCH] Add additional key for items of type array with the type of each element we will default to 'string' right now in order to make our swagger spec valid. --- openapi_codec/encode.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/openapi_codec/encode.py b/openapi_codec/encode.py index 82b9997..8c7396a 100644 --- a/openapi_codec/encode.py +++ b/openapi_codec/encode.py @@ -115,16 +115,20 @@ def _get_parameters(link, encoding): 'required': field.required, 'in': 'formData', 'description': field.description, - 'type': field.type or 'string' + 'type': field.type or 'string', } + if field.type == 'array': + parameter['items'] = {'type': 'string'} parameters.append(parameter) else: # Expand coreapi fields with location='form' into a single swagger # parameter, with a schema containing multiple properties. schema_property = { 'description': field.description, - 'type': field.type or 'string' + 'type': field.type or 'string', } + if field.type == 'array': + schema_property['items'] = {'type': 'string'} properties[field.name] = schema_property if field.required: required.append(field.name) @@ -148,8 +152,10 @@ def _get_parameters(link, encoding): 'required': field.required, 'in': location, 'description': field.description, - 'type': field.type or 'string' + 'type': field.type or 'string', } + if field.type == 'array': + parameter['items'] = {'type': 'string'} parameters.append(parameter) if properties: