Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.

Commit 0de50b2

Browse files
committed
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.
1 parent a045b2d commit 0de50b2

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

openapi_codec/encode.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,26 @@ def _get_parameters(link, encoding):
115115
'required': field.required,
116116
'in': 'formData',
117117
'description': field.description,
118-
'type': field.type or 'string'
119118
}
119+
if field.type:
120+
parameter['type'] = field.type
121+
if field.type == 'array':
122+
parameter['items'] = {'type': 'string'}
123+
else:
124+
parameter['type'] = 'string'
120125
parameters.append(parameter)
121126
else:
122127
# Expand coreapi fields with location='form' into a single swagger
123128
# parameter, with a schema containing multiple properties.
124129
schema_property = {
125130
'description': field.description,
126-
'type': field.type or 'string'
127131
}
132+
if field.type:
133+
schema_property['type'] = field.type
134+
if field.type == 'array':
135+
schema_property['items'] = {'type': 'string'}
136+
else:
137+
schema_property['type'] = 'string'
128138
properties[field.name] = schema_property
129139
if field.required:
130140
required.append(field.name)
@@ -148,8 +158,13 @@ def _get_parameters(link, encoding):
148158
'required': field.required,
149159
'in': location,
150160
'description': field.description,
151-
'type': field.type or 'string'
152161
}
162+
if field.type:
163+
parameter['type'] = field.type
164+
if field.type == 'array':
165+
parameter['items'] = {'type': 'string'}
166+
else:
167+
parameter['type'] = 'string'
153168
parameters.append(parameter)
154169

155170
if properties:

0 commit comments

Comments
 (0)