Skip to content

Commit 2de9c6c

Browse files
api-clients-generation-pipeline[bot]skarimoci.datadog-api-spec
authored
Ensure clients can handle empty oneOf objects (#2702)
* handle empty oneof * handle empty object matches * lint * Regenerate client from commit 60bc9127 of spec repo --------- Co-authored-by: Sherzod Karimov <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 46c520f commit 2de9c6c

File tree

40 files changed

+177
-53
lines changed

40 files changed

+177
-53
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2024-09-30 13:56:52.513837",
8-
"spec_repo_commit": "eb66b1cf"
7+
"regenerated": "2024-09-30 14:37:39.238144",
8+
"spec_repo_commit": "60bc9127"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2024-09-30 13:56:52.527994",
13-
"spec_repo_commit": "eb66b1cf"
12+
"regenerated": "2024-09-30 14:37:39.252667",
13+
"spec_repo_commit": "60bc9127"
1414
}
1515
}
1616
}

.generator/src/generator/templates/model_oneof.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (obj *{{ name }}) UnmarshalJSON(data []byte) error {
6363
if err == nil {
6464
if obj.{{ attributeName }} != nil {% if oneOf.get("type", "object") == "object" %}&& obj.{{ attributeName }}.UnparsedObject == nil {% endif %}{
6565
json{{ attributeName }}, _ := datadog.Marshal(obj.{{ attributeName }})
66-
if string(json{{ attributeName }}) == "{}" { // empty struct
66+
if string(json{{ attributeName }}) == "{}"{% if not oneOf|is_primitive and not oneOf.required %} && string(data) != "{}" {% endif %} { // empty struct
6767
obj.{{ attributeName }} = nil
6868
} else {
6969
match++

api/datadogV1/model_distribution_point_item.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (obj *DistributionPointItem) UnmarshalJSON(data []byte) error {
5353
if err == nil {
5454
if obj.DistributionPointData != nil {
5555
jsonDistributionPointData, _ := datadog.Marshal(obj.DistributionPointData)
56-
if string(jsonDistributionPointData) == "{}" { // empty struct
56+
if string(jsonDistributionPointData) == "{}" && string(data) != "{}" { // empty struct
5757
obj.DistributionPointData = nil
5858
} else {
5959
match++

api/datadogV1/model_shared_dashboard_invites_data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (obj *SharedDashboardInvitesData) UnmarshalJSON(data []byte) error {
5353
if err == nil {
5454
if obj.SharedDashboardInvitesDataList != nil {
5555
jsonSharedDashboardInvitesDataList, _ := datadog.Marshal(obj.SharedDashboardInvitesDataList)
56-
if string(jsonSharedDashboardInvitesDataList) == "{}" { // empty struct
56+
if string(jsonSharedDashboardInvitesDataList) == "{}" && string(data) != "{}" { // empty struct
5757
obj.SharedDashboardInvitesDataList = nil
5858
} else {
5959
match++

api/datadogV1/model_widget_time.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (obj *WidgetTime) UnmarshalJSON(data []byte) error {
4242
if err == nil {
4343
if obj.WidgetLegacyLiveSpan != nil && obj.WidgetLegacyLiveSpan.UnparsedObject == nil {
4444
jsonWidgetLegacyLiveSpan, _ := datadog.Marshal(obj.WidgetLegacyLiveSpan)
45-
if string(jsonWidgetLegacyLiveSpan) == "{}" { // empty struct
45+
if string(jsonWidgetLegacyLiveSpan) == "{}" && string(data) != "{}" { // empty struct
4646
obj.WidgetLegacyLiveSpan = nil
4747
} else {
4848
match++

api/datadogV2/model_api_key_response_included_item.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (obj *APIKeyResponseIncludedItem) UnmarshalJSON(data []byte) error {
3636
if err == nil {
3737
if obj.User != nil && obj.User.UnparsedObject == nil {
3838
jsonUser, _ := datadog.Marshal(obj.User)
39-
if string(jsonUser) == "{}" { // empty struct
39+
if string(jsonUser) == "{}" && string(data) != "{}" { // empty struct
4040
obj.User = nil
4141
} else {
4242
match++

api/datadogV2/model_application_key_response_included_item.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (obj *ApplicationKeyResponseIncludedItem) UnmarshalJSON(data []byte) error
4242
if err == nil {
4343
if obj.User != nil && obj.User.UnparsedObject == nil {
4444
jsonUser, _ := datadog.Marshal(obj.User)
45-
if string(jsonUser) == "{}" { // empty struct
45+
if string(jsonUser) == "{}" && string(data) != "{}" { // empty struct
4646
obj.User = nil
4747
} else {
4848
match++

api/datadogV2/model_auth_n_mapping_included.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (obj *AuthNMappingIncluded) UnmarshalJSON(data []byte) error {
7676
if err == nil {
7777
if obj.AuthNMappingTeam != nil && obj.AuthNMappingTeam.UnparsedObject == nil {
7878
jsonAuthNMappingTeam, _ := datadog.Marshal(obj.AuthNMappingTeam)
79-
if string(jsonAuthNMappingTeam) == "{}" { // empty struct
79+
if string(jsonAuthNMappingTeam) == "{}" && string(data) != "{}" { // empty struct
8080
obj.AuthNMappingTeam = nil
8181
} else {
8282
match++

api/datadogV2/model_ci_app_aggregate_bucket_value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (obj *CIAppAggregateBucketValue) UnmarshalJSON(data []byte) error {
7676
if err == nil {
7777
if obj.CIAppAggregateBucketValueTimeseries != nil {
7878
jsonCIAppAggregateBucketValueTimeseries, _ := datadog.Marshal(obj.CIAppAggregateBucketValueTimeseries)
79-
if string(jsonCIAppAggregateBucketValueTimeseries) == "{}" { // empty struct
79+
if string(jsonCIAppAggregateBucketValueTimeseries) == "{}" && string(data) != "{}" { // empty struct
8080
obj.CIAppAggregateBucketValueTimeseries = nil
8181
} else {
8282
match++

api/datadogV2/model_container_image_item.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (obj *ContainerImageItem) UnmarshalJSON(data []byte) error {
3636
if err == nil {
3737
if obj.ContainerImage != nil && obj.ContainerImage.UnparsedObject == nil {
3838
jsonContainerImage, _ := datadog.Marshal(obj.ContainerImage)
39-
if string(jsonContainerImage) == "{}" { // empty struct
39+
if string(jsonContainerImage) == "{}" && string(data) != "{}" { // empty struct
4040
obj.ContainerImage = nil
4141
} else {
4242
match++
@@ -53,7 +53,7 @@ func (obj *ContainerImageItem) UnmarshalJSON(data []byte) error {
5353
if err == nil {
5454
if obj.ContainerImageGroup != nil && obj.ContainerImageGroup.UnparsedObject == nil {
5555
jsonContainerImageGroup, _ := datadog.Marshal(obj.ContainerImageGroup)
56-
if string(jsonContainerImageGroup) == "{}" { // empty struct
56+
if string(jsonContainerImageGroup) == "{}" && string(data) != "{}" { // empty struct
5757
obj.ContainerImageGroup = nil
5858
} else {
5959
match++

0 commit comments

Comments
 (0)