Skip to content

Commit 008536d

Browse files
committed
Fix oneOf handling for lists of primitives in model_utils
1 parent 3c1a8a5 commit 008536d

File tree

2 files changed

+76
-18
lines changed

2 files changed

+76
-18
lines changed

.generator/src/generator/templates/model_utils.j2

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ def composed_model_input_classes(cls):
7575
This function returns a list of the possible models that can be accepted as
7676
inputs.
7777
"""
78+
# Handle list types (e.g., [str], [float])
79+
if isinstance(cls, list):
80+
return [cls]
7881
if issubclass(cls, ModelSimple) or cls in PRIMITIVE_TYPES:
7982
return [cls]
8083
elif issubclass(cls, ModelNormal):
@@ -1557,17 +1560,43 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
15571560
# Empty data
15581561
oneof_instances.append(list_oneof_instance)
15591562
continue
1560-
for arg in model_arg:
1561-
if constant_kwargs.get("_spec_property_naming"):
1562-
oneof_instance = oneof_class(
1563-
**change_keys_js_to_python(arg, oneof_class), **constant_kwargs
1563+
1564+
# Check if inner type is primitive - treat same as lines 1590-1599
1565+
if oneof_class in PRIMITIVE_TYPES:
1566+
# Handle list of primitives (e.g., [str], [float])
1567+
for arg in model_arg:
1568+
oneof_instance = validate_and_convert_types(
1569+
arg,
1570+
(oneof_class,),
1571+
constant_kwargs.get("_path_to_item", ()),
1572+
constant_kwargs.get("_spec_property_naming", False),
1573+
constant_kwargs.get("_check_type", True),
1574+
configuration=constant_kwargs.get("_configuration"),
15641575
)
1565-
else:
1566-
oneof_instance = oneof_class(**arg, **constant_kwargs)
1567-
if not oneof_instance._unparsed:
15681576
list_oneof_instance.append(oneof_instance)
1569-
if list_oneof_instance:
1570-
oneof_instances.append(list_oneof_instance)
1577+
if list_oneof_instance:
1578+
oneof_instances.append(list_oneof_instance)
1579+
elif inspect.isclass(oneof_class) and issubclass(oneof_class, ModelSimple):
1580+
# Handle list of ModelSimple
1581+
for arg in model_arg:
1582+
oneof_instance = oneof_class(arg, **constant_kwargs)
1583+
if not oneof_instance._unparsed:
1584+
list_oneof_instance.append(oneof_instance)
1585+
if list_oneof_instance:
1586+
oneof_instances.append(list_oneof_instance)
1587+
else:
1588+
# Handle list of complex objects (ModelNormal, ModelComposed)
1589+
for arg in model_arg:
1590+
if constant_kwargs.get("_spec_property_naming"):
1591+
oneof_instance = oneof_class(
1592+
**change_keys_js_to_python(arg, oneof_class), **constant_kwargs
1593+
)
1594+
else:
1595+
oneof_instance = oneof_class(**arg, **constant_kwargs)
1596+
if not oneof_instance._unparsed:
1597+
list_oneof_instance.append(oneof_instance)
1598+
if list_oneof_instance:
1599+
oneof_instances.append(list_oneof_instance)
15711600
elif issubclass(oneof_class, ModelSimple):
15721601
if model_arg is not None:
15731602
oneof_instance = oneof_class(model_arg, **constant_kwargs)

src/datadog_api_client/model_utils.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def composed_model_input_classes(cls):
7777
This function returns a list of the possible models that can be accepted as
7878
inputs.
7979
"""
80+
# Handle list types (e.g., [str], [float])
81+
if isinstance(cls, list):
82+
return [cls]
8083
if issubclass(cls, ModelSimple) or cls in PRIMITIVE_TYPES:
8184
return [cls]
8285
elif issubclass(cls, ModelNormal):
@@ -1571,17 +1574,43 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
15711574
# Empty data
15721575
oneof_instances.append(list_oneof_instance)
15731576
continue
1574-
for arg in model_arg:
1575-
if constant_kwargs.get("_spec_property_naming"):
1576-
oneof_instance = oneof_class(
1577-
**change_keys_js_to_python(arg, oneof_class), **constant_kwargs
1577+
1578+
# Check if inner type is primitive - treat same as lines 1590-1599
1579+
if oneof_class in PRIMITIVE_TYPES:
1580+
# Handle list of primitives (e.g., [str], [float])
1581+
for arg in model_arg:
1582+
oneof_instance = validate_and_convert_types(
1583+
arg,
1584+
(oneof_class,),
1585+
constant_kwargs.get("_path_to_item", ()),
1586+
constant_kwargs.get("_spec_property_naming", False),
1587+
constant_kwargs.get("_check_type", True),
1588+
configuration=constant_kwargs.get("_configuration"),
15781589
)
1579-
else:
1580-
oneof_instance = oneof_class(**arg, **constant_kwargs)
1581-
if not oneof_instance._unparsed:
15821590
list_oneof_instance.append(oneof_instance)
1583-
if list_oneof_instance:
1584-
oneof_instances.append(list_oneof_instance)
1591+
if list_oneof_instance:
1592+
oneof_instances.append(list_oneof_instance)
1593+
elif inspect.isclass(oneof_class) and issubclass(oneof_class, ModelSimple):
1594+
# Handle list of ModelSimple
1595+
for arg in model_arg:
1596+
oneof_instance = oneof_class(arg, **constant_kwargs)
1597+
if not oneof_instance._unparsed:
1598+
list_oneof_instance.append(oneof_instance)
1599+
if list_oneof_instance:
1600+
oneof_instances.append(list_oneof_instance)
1601+
else:
1602+
# Handle list of complex objects (ModelNormal, ModelComposed)
1603+
for arg in model_arg:
1604+
if constant_kwargs.get("_spec_property_naming"):
1605+
oneof_instance = oneof_class(
1606+
**change_keys_js_to_python(arg, oneof_class), **constant_kwargs
1607+
)
1608+
else:
1609+
oneof_instance = oneof_class(**arg, **constant_kwargs)
1610+
if not oneof_instance._unparsed:
1611+
list_oneof_instance.append(oneof_instance)
1612+
if list_oneof_instance:
1613+
oneof_instances.append(list_oneof_instance)
15851614
elif issubclass(oneof_class, ModelSimple):
15861615
if model_arg is not None:
15871616
oneof_instance = oneof_class(model_arg, **constant_kwargs)

0 commit comments

Comments
 (0)