Skip to content

Commit b0b95aa

Browse files
committed
Fixed array and relation types to show its child correct type, instead of always string.
1 parent baa97e0 commit b0b95aa

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

openapi_codec/encode.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,21 @@ def _get_field_type(field):
118118
if field.schema is None:
119119
return 'string'
120120

121+
return _get_field_type_name(field.schema.__class__)
122+
123+
124+
def _get_field_type_name(type):
125+
if type is None:
126+
return 'string'
127+
121128
return {
122129
coreschema.String: 'string',
123130
coreschema.Integer: 'integer',
124131
coreschema.Number: 'number',
125132
coreschema.Boolean: 'boolean',
126133
coreschema.Array: 'array',
127134
coreschema.Object: 'object',
128-
}.get(field.schema.__class__, 'string')
135+
}.get(type, 'string')
129136

130137

131138
def _get_parameters(link, encoding):
@@ -162,7 +169,14 @@ def _get_parameters(link, encoding):
162169
'type': field_type,
163170
}
164171
if field_type == 'array':
165-
schema_property['items'] = {'type': 'string'}
172+
type_string = 'string'
173+
if hasattr(field, "schema") and hasattr(field.schema, "items") and field.schema.items is not None:
174+
if isinstance(field.schema.items, type):
175+
model_type = field.schema.items
176+
else:
177+
model_type = field.schema.items.__class__
178+
type_string = _get_field_type_name(model_type)
179+
schema_property['items'] = {'type': type_string}
166180
properties[field.name] = schema_property
167181
if field.required:
168182
required.append(field.name)

0 commit comments

Comments
 (0)