Skip to content

Commit bcda8e4

Browse files
committed
fix(python): Fix sanitize_for_serialization code generation for python client
1 parent 99f49c2 commit bcda8e4

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

modules/openapi-generator/src/main/resources/python/api_client.mustache

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -379,28 +379,24 @@ class ApiClient:
379379
return obj.isoformat()
380380
elif isinstance(obj, decimal.Decimal):
381381
return str(obj)
382-
383382
elif isinstance(obj, dict):
384-
obj_dict = obj
383+
return {
384+
key: self.sanitize_for_serialization(val)
385+
for key, val in obj.items()
386+
}
387+
388+
# Convert model obj to dict except
389+
# attributes `openapi_types`, `attribute_map`
390+
# and attributes which value is not None.
391+
# Convert attribute name to json key in
392+
# model definition for request.
393+
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
394+
obj_dict = obj.to_dict()
385395
else:
386-
# Convert model obj to dict except
387-
# attributes `openapi_types`, `attribute_map`
388-
# and attributes which value is not None.
389-
# Convert attribute name to json key in
390-
# model definition for request.
391-
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
392-
obj_dict = obj.to_dict()
393-
else:
394-
obj_dict = obj.__dict__
396+
obj_dict = obj.__dict__
395397

396-
if isinstance(obj_dict, list):
397-
# here we handle instances that can either be a list or something else, and only became a real list by calling to_dict()
398-
return self.sanitize_for_serialization(obj_dict)
398+
return self.sanitize_for_serialization(obj_dict)
399399

400-
return {
401-
key: self.sanitize_for_serialization(val)
402-
for key, val in obj_dict.items()
403-
}
404400

405401
def deserialize(self, response_text: str, response_type: str, content_type: Optional[str]):
406402
"""Deserializes response into an object.

0 commit comments

Comments
 (0)