Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions .generator/src/generator/templates/model_utils.j2
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def composed_model_input_classes(cls):
This function returns a list of the possible models that can be accepted as
inputs.
"""
# Handle list types (e.g., [str], [float])
if isinstance(cls, list):
return [cls]
if issubclass(cls, ModelSimple) or cls in PRIMITIVE_TYPES:
return [cls]
elif issubclass(cls, ModelNormal):
Expand Down Expand Up @@ -1557,17 +1560,44 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
# Empty data
oneof_instances.append(list_oneof_instance)
continue
for arg in model_arg:
if constant_kwargs.get("_spec_property_naming"):
oneof_instance = oneof_class(
**change_keys_js_to_python(arg, oneof_class), **constant_kwargs

# Check if inner type is primitive - follows same pattern as complex objects:
# https://github.com/DataDog/datadog-api-client-python/blob/008536d34760ce096e118edc54df613d82194529/.generator/src/generator/templates/model_utils.j2#L1590-L1599
if oneof_class in PRIMITIVE_TYPES:
# Handle list of primitives (e.g., [str], [float])
for arg in model_arg:
oneof_instance = validate_and_convert_types(
arg,
(oneof_class,),
constant_kwargs.get("_path_to_item", ()),
constant_kwargs.get("_spec_property_naming", False),
constant_kwargs.get("_check_type", True),
configuration=constant_kwargs.get("_configuration"),
)
else:
oneof_instance = oneof_class(**arg, **constant_kwargs)
if not oneof_instance._unparsed:
list_oneof_instance.append(oneof_instance)
if list_oneof_instance:
oneof_instances.append(list_oneof_instance)
if list_oneof_instance:
oneof_instances.append(list_oneof_instance)
elif inspect.isclass(oneof_class) and issubclass(oneof_class, ModelSimple):
# Handle list of ModelSimple
for arg in model_arg:
oneof_instance = oneof_class(arg, **constant_kwargs)
if not oneof_instance._unparsed:
list_oneof_instance.append(oneof_instance)
if list_oneof_instance:
oneof_instances.append(list_oneof_instance)
else:
# Handle list of complex objects (ModelNormal, ModelComposed)
for arg in model_arg:
if constant_kwargs.get("_spec_property_naming"):
oneof_instance = oneof_class(
**change_keys_js_to_python(arg, oneof_class), **constant_kwargs
)
else:
oneof_instance = oneof_class(**arg, **constant_kwargs)
if not oneof_instance._unparsed:
list_oneof_instance.append(oneof_instance)
if list_oneof_instance:
oneof_instances.append(list_oneof_instance)
elif issubclass(oneof_class, ModelSimple):
if model_arg is not None:
oneof_instance = oneof_class(model_arg, **constant_kwargs)
Expand Down
48 changes: 39 additions & 9 deletions src/datadog_api_client/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def composed_model_input_classes(cls):
This function returns a list of the possible models that can be accepted as
inputs.
"""
# Handle list types (e.g., [str], [float])
if isinstance(cls, list):
return [cls]
if issubclass(cls, ModelSimple) or cls in PRIMITIVE_TYPES:
return [cls]
elif issubclass(cls, ModelNormal):
Expand Down Expand Up @@ -1571,17 +1574,44 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
# Empty data
oneof_instances.append(list_oneof_instance)
continue
for arg in model_arg:
if constant_kwargs.get("_spec_property_naming"):
oneof_instance = oneof_class(
**change_keys_js_to_python(arg, oneof_class), **constant_kwargs

# Check if inner type is primitive - follows same pattern as complex objects:
# https://github.com/DataDog/datadog-api-client-python/blob/008536d34760ce096e118edc54df613d82194529/.generator/src/generator/templates/model_utils.j2#L1590-L1599
if oneof_class in PRIMITIVE_TYPES:
# Handle list of primitives (e.g., [str], [float])
for arg in model_arg:
oneof_instance = validate_and_convert_types(
arg,
(oneof_class,),
constant_kwargs.get("_path_to_item", ()),
constant_kwargs.get("_spec_property_naming", False),
constant_kwargs.get("_check_type", True),
configuration=constant_kwargs.get("_configuration"),
)
else:
oneof_instance = oneof_class(**arg, **constant_kwargs)
if not oneof_instance._unparsed:
list_oneof_instance.append(oneof_instance)
if list_oneof_instance:
oneof_instances.append(list_oneof_instance)
if list_oneof_instance:
oneof_instances.append(list_oneof_instance)
elif inspect.isclass(oneof_class) and issubclass(oneof_class, ModelSimple):
# Handle list of ModelSimple
for arg in model_arg:
oneof_instance = oneof_class(arg, **constant_kwargs)
if not oneof_instance._unparsed:
list_oneof_instance.append(oneof_instance)
if list_oneof_instance:
oneof_instances.append(list_oneof_instance)
else:
# Handle list of complex objects (ModelNormal, ModelComposed)
for arg in model_arg:
if constant_kwargs.get("_spec_property_naming"):
oneof_instance = oneof_class(
**change_keys_js_to_python(arg, oneof_class), **constant_kwargs
)
else:
oneof_instance = oneof_class(**arg, **constant_kwargs)
if not oneof_instance._unparsed:
list_oneof_instance.append(oneof_instance)
if list_oneof_instance:
oneof_instances.append(list_oneof_instance)
elif issubclass(oneof_class, ModelSimple):
if model_arg is not None:
oneof_instance = oneof_class(model_arg, **constant_kwargs)
Expand Down