8000 add descriptions for properies · dd/python-openapi-codec@0ca89a5 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 0ca89a5

Browse files
author
dd
committed
add descriptions for properies
1 parent 3ef7e87 commit 0ca89a5

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

openapi_codec/encode.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,33 +144,35 @@ def _get_property_type(the_schema):
144144

145145

146146
def _field_properties_for_fields(properties):
147-
field_properties = {}
148-
for k in properties:
149-
field_properties[k] = {
150-
'type': _get_property_type(properties[k])
147+
result = {}
148+
for prop, data in properties.items():
149+
result[prop] = {
150+
'type': _get_property_type(data),
151+
'description': _get_field_description(data),
151152
}
152153

153-
if field_properties[k]['type'] == "object":
154-
field_properties[k]['properties'] = _field_properties_for_fields(properties[k].properties)
154+
if hasattr(data, 'required'):
155+
result[prop]['required'] = getattr(data, 'required', False)
155156

156-
elif field_properties[k]['type'] == "array":
157-
# field_properties[k]['items'] = _field_properties_for_fields(properties[k].items)
157+
if result[prop]['type'] == "object":
158+
result[prop]['properties'] = _field_properties_for_fields(data.properties)
158159

159-
if hasattr(properties[k].items, 'properties'):
160+
elif result[prop]['type'] == "array":
161+
if hasattr(properties[prop].items, 'properties'):
160162
# the array contains object instances, we need to inspect their properties
161-
field_properties[k]['items'] = {
163+
result[prop]['items'] = {
162164
'type': 'object',
163165
'properties': _field_properties_for_fields(
164-
properties[k].items.properties
166+
data.items.properties
165167
)
166168
}
167169
else:
168170
# the array contains primitive types
169-
field_properties[k]['items'] = {
170-
'type': _get_property_type(properties[k].items),
171+
result[prop]['items'] = {
172+
'type': _get_property_type(data.items),
171173
}
172174

173-
return field_properties
175+
return result
174176

175177

176178
def _get_parameters(link, encoding):

0 commit comments

Comments
 (0)
0