Skip to content

Commit 5fa1a32

Browse files
vvbcode-lucidal58
andauthored
[python] Fixes a breakage while deserializing the read-only attributes (#10155)
* fixes a breakage while deserializing the read-only attributes * updating generated samples * taking care of the PR comments * updating samples * protect against cases where _spec_property_naming may not be present * updating samples * adding tests for this issue * other generated files * taking care of the comments * updating the generated samples Co-authored-by: Aanisha Mishra <[email protected]>
1 parent fd63da9 commit 5fa1a32

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

.generator/templates/model_utils.mustache

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,10 @@ def get_allof_instances(self, model_args, constant_args):
14501450
for allof_class in self._composed_schemas['allOf']:
14511451

14521452
try:
1453-
allof_instance = allof_class(**model_args, **constant_args)
1453+
if constant_args.get('_spec_property_naming'):
1454+
allof_instance = allof_class._from_openapi_data(**model_args, **constant_args)
1455+
else:
1456+
allof_instance = allof_class(**model_args, **constant_args)
14541457
composed_instances.append(allof_instance)
14551458
except Exception as ex:
14561459
raise ApiValueError(
@@ -1512,10 +1515,16 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
15121515

15131516
try:
15141517
if not single_value_input:
1515-
oneof_instance = oneof_class(**model_kwargs, **constant_kwargs)
1518+
if constant_kwargs.get('_spec_property_naming'):
1519+
oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs)
1520+
else:
1521+
oneof_instance = oneof_class(**model_kwargs, **constant_kwargs)
15161522
else:
15171523
if issubclass(oneof_class, ModelSimple):
1518-
oneof_instance = oneof_class(model_arg, **constant_kwargs)
1524+
if constant_kwargs.get('_spec_property_naming'):
1525+
oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs)
1526+
else:
1527+
oneof_instance = oneof_class(model_arg, **constant_kwargs)
15191528
elif oneof_class in PRIMITIVE_TYPES:
15201529
oneof_instance = validate_and_convert_types(
15211530
model_arg,
@@ -1570,7 +1579,10 @@ def get_anyof_instances(self, model_args, constant_args):
15701579
continue
15711580

15721581
try:
1573-
anyof_instance = anyof_class(**model_args, **constant_args)
1582+
if constant_args.get('_spec_property_naming'):
1583+
anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args)
1584+
else:
1585+
anyof_instance = anyof_class(**model_args, **constant_args)
15741586
anyof_instances.append(anyof_instance)
15751587
except Exception:
15761588
pass

0 commit comments

Comments
 (0)