Skip to content

Commit 7670114

Browse files
nogatesclaudeci.datadog-api-spec
authored
Fix nullable UUID type mismatch in Go code generator (#4172)
* Fix nullable UUID type mismatch in Go code generator Nullable UUID fields (format: uuid, nullable: true) were being mapped to NullableString, causing getter/setter methods to return *string while the method signatures expected uuid.UUID — a compile error. Add a dedicated NullableUUID type to utils.j2 and update formatter.py to use it for nullable uuid fields instead of NullableString. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * pre-commit fixes --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent fb8950e commit 7670114

3 files changed

Lines changed: 89 additions & 1 deletion

File tree

.generator/src/generator/formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def simple_type(schema, render_nullable=False, render_new=False):
155155
"date": "time.Time" if not nullable else f"{nullable_prefix}Time",
156156
"date-time": "time.Time" if not nullable else f"{nullable_prefix}Time",
157157
"binary": "_io.Reader",
158-
"uuid": "uuid.UUID" if not nullable else f"{nullable_prefix}String",
158+
"uuid": "uuid.UUID" if not nullable else f"{nullable_prefix}UUID",
159159
}.get(type_format, "string" if not nullable else f"{nullable_prefix}String")
160160
if type_name == "boolean":
161161
return "bool" if not nullable else f"{nullable_prefix}Bool"

.generator/src/generator/templates/utils.j2

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,50 @@ func PtrTime(v time.Time) *time.Time { return &v }
3939
// PtrUUID is helper routine that returns a pointer to given UUID value.
4040
func PtrUUID(v uuid.UUID) *uuid.UUID { return &v }
4141

42+
// NullableUUID is a struct to hold a nullable UUID value.
43+
type NullableUUID struct {
44+
value *uuid.UUID
45+
isSet bool
46+
}
47+
48+
// Get returns the value associated with the nullable UUID.
49+
func (v NullableUUID) Get() *uuid.UUID {
50+
return v.value
51+
}
52+
53+
// Set sets the value associated with the nullable UUID.
54+
func (v *NullableUUID) Set(val *uuid.UUID) {
55+
v.value = val
56+
v.isSet = true
57+
}
58+
59+
// IsSet returns true if the value has been set.
60+
func (v NullableUUID) IsSet() bool {
61+
return v.isSet
62+
}
63+
64+
// Unset resets fields of the nullable UUID.
65+
func (v *NullableUUID) Unset() {
66+
v.value = nil
67+
v.isSet = false
68+
}
69+
70+
// NewNullableUUID instantiates a new nullable UUID.
71+
func NewNullableUUID(val *uuid.UUID) *NullableUUID {
72+
return &NullableUUID{value: val, isSet: true}
73+
}
74+
75+
// MarshalJSON serializes the associated value.
76+
func (v NullableUUID) MarshalJSON() ([]byte, error) {
77+
return Marshal(v.value)
78+
}
79+
80+
// UnmarshalJSON deserializes to the associated value.
81+
func (v *NullableUUID) UnmarshalJSON(src []byte) error {
82+
v.isSet = true
83+
return Unmarshal(src, &v.value)
84+
}
85+
4286
// PaginationResult pagination item helper struct
4387
type PaginationResult[T any] struct {
4488
Item T

api/datadog/utils.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,50 @@ func PtrTime(v time.Time) *time.Time { return &v }
4343
// PtrUUID is helper routine that returns a pointer to given UUID value.
4444
func PtrUUID(v uuid.UUID) *uuid.UUID { return &v }
4545

46+
// NullableUUID is a struct to hold a nullable UUID value.
47+
type NullableUUID struct {
48+
value *uuid.UUID
49+
isSet bool
50+
}
51+
52+
// Get returns the value associated with the nullable UUID.
53+
func (v NullableUUID) Get() *uuid.UUID {
54+
return v.value
55+
}
56+
57+
// Set sets the value associated with the nullable UUID.
58+
func (v *NullableUUID) Set(val *uuid.UUID) {
59+
v.value = val
60+
v.isSet = true
61+
}
62+
63+
// IsSet returns true if the value has been set.
64+
func (v NullableUUID) IsSet() bool {
65+
return v.isSet
66+
}
67+
68+
// Unset resets fields of the nullable UUID.
69+
func (v *NullableUUID) Unset() {
70+
v.value = nil
71+
v.isSet = false
72+
}
73+
74+
// NewNullableUUID instantiates a new nullable UUID.
75+
func NewNullableUUID(val *uuid.UUID) *NullableUUID {
76+
return &NullableUUID{value: val, isSet: true}
77+
}
78+
79+
// MarshalJSON serializes the associated value.
80+
func (v NullableUUID) MarshalJSON() ([]byte, error) {
81+
return Marshal(v.value)
82+
}
83+
84+
// UnmarshalJSON deserializes to the associated value.
85+
func (v *NullableUUID) UnmarshalJSON(src []byte) error {
86+
v.isSet = true
87+
return Unmarshal(src, &v.value)
88+
}
89+
4690
// PaginationResult pagination item helper struct
4791
type PaginationResult[T any] struct {
4892
Item T

0 commit comments

Comments
 (0)