Skip to content

Commit bd00ec5

Browse files
author
dd
committed
merge
2 parents 8a7a098 + 5ae44cc commit bd00ec5

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

openapi_codec/encode.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,26 @@ def _get_field_format(field):
132132
return field.schema and getattr(field.schema, 'format', None)
133133

134134

135+
def _get_property_type(the_schema):
136+
return {
137+
coreschema.String: 'string',
138+
coreschema.Integer: 'integer',
139+
coreschema.Number: 'number',
140+
coreschema.Boolean: 'boolean',
141+
coreschema.Array: 'array',
142+
coreschema.Object: 'object',
143+
}.get(the_schema.__class__, 'string')
144+
145+
146+
def _field_properties_for_fields(field__schema_properties):
147+
field_properties = {}
148+
for k in field__schema_properties:
149+
field_properties[k] = {
150+
'type': _get_property_type(field__schema_properties[k])
151+
}
152+
return field_properties
153+
154+
135155
def _get_parameters(link, encoding):
136156
"""
137157
Generates Swagger Parameter Item object.
@@ -168,8 +188,28 @@ def _get_parameters(link, encoding):
168188
'description': field_description,
169189
'type': field_type,
170190
}
191+
if field_type == 'object':
192+
field_properties = _field_properties_for_fields(field.schema.properties)
193+
schema_property = {
194+
'description': field_description,
195+
'type': field_type,
196+
'properties': field_properties
197+
}
171198
if field_type == 'array':
172-
schema_property['items'] = {'type': 'string'}
199+
if hasattr(field.schema.items, 'properties'):
200+
# the array contains object instances, we need to inspect their properties
201+
field_properties = _field_properties_for_fields(
202+
field.schema.items.properties
203+
)
204+
schema_property['items'] = {
205+
'type': 'object',
206+
'properties': field_properties
207+
}
208+
else:
209+
# the array contains primitive types
210+
schema_property['items'] = {
211+
'type': _get_property_type(field.schema.items),
212+
}
173213
properties[field.name] = schema_property
174214
if field.required:
175215
required.append(field.name)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy