Skip to content

Commit 894008f

Browse files
[Python] Correct sanitize_for_serialization in python generator for list in oneOf schema elements, fixes #18106 (#19405)
* correct sanitize_for_serialization in python generator, fixes #18106 The method did not consider the objects created for oneOf schemata. If one of the cases was a list, to_dict would return it instead of something that has an items() method. * generate new samples
1 parent 5f63385 commit 894008f

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ class ApiClient:
390390
else:
391391
obj_dict = obj.__dict__
392392

393+
if isinstance(obj_dict, list):
394+
# here we handle instances that can either be a list or something else, and only became a real list by calling to_dict()
395+
return self.sanitize_for_serialization(obj_dict)
396+
393397
return {
394398
key: self.sanitize_for_serialization(val)
395399
for key, val in obj_dict.items()

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ def sanitize_for_serialization(self, obj):
383383
else:
384384
obj_dict = obj.__dict__
385385

386+
if isinstance(obj_dict, list):
387+
# here we handle instances that can either be a list or something else, and only became a real list by calling to_dict()
388+
return self.sanitize_for_serialization(obj_dict)
389+
386390
return {
387391
key: self.sanitize_for_serialization(val)
388392
for key, val in obj_dict.items()

samples/client/echo_api/python/openapi_client/api_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ def sanitize_for_serialization(self, obj):
383383
else:
384384
obj_dict = obj.__dict__
385385

386+
if isinstance(obj_dict, list):
387+
# here we handle instances that can either be a list or something else, and only became a real list by calling to_dict()
388+
return self.sanitize_for_serialization(obj_dict)
389+
386390
return {
387391
key: self.sanitize_for_serialization(val)
388392
for key, val in obj_dict.items()

samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ def sanitize_for_serialization(self, obj):
385385
else:
386386
obj_dict = obj.__dict__
387387

388+
if isinstance(obj_dict, list):
389+
# here we handle instances that can either be a list or something else, and only became a real list by calling to_dict()
390+
return self.sanitize_for_serialization(obj_dict)
391+
388392
return {
389393
key: self.sanitize_for_serialization(val)
390394
for key, val in obj_dict.items()

samples/openapi3/client/petstore/python/petstore_api/api_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ def sanitize_for_serialization(self, obj):
382382
else:
383383
obj_dict = obj.__dict__
384384

385+
if isinstance(obj_dict, list):
386+
# here we handle instances that can either be a list or something else, and only became a real list by calling to_dict()
387+
return self.sanitize_for_serialization(obj_dict)
388+
385389
return {
386390
key: self.sanitize_for_serialization(val)
387391
for key, val in obj_dict.items()

0 commit comments

Comments
 (0)