Skip to content

Commit ce7c15c

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Specify accepted types for UpsertRows values (#3567)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 0a3cca2 commit ce7c15c

5 files changed

Lines changed: 143 additions & 21 deletions

File tree

.generator/schemas/v2/openapi.yaml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7075,19 +7075,27 @@ components:
70757075
BatchUpsertRowsRequestDataAttributes:
70767076
description: Attributes containing row data values for row creation or update
70777077
operations.
7078+
example:
7079+
values: {}
70787080
properties:
70797081
values:
70807082
additionalProperties:
7081-
x-required-field: true
7082-
description: Key-value pairs representing row data, where keys are field
7083-
names from the schema.
7084-
example:
7085-
example_key_value: primary_key_value
7086-
name: row_name
7083+
$ref: '#/components/schemas/BatchUpsertRowsRequestDataAttributesValue'
7084+
description: Key-value pairs representing row data, where keys are schema
7085+
field names and values match the corresponding column types.
70877086
type: object
70887087
required:
70897088
- values
70907089
type: object
7090+
BatchUpsertRowsRequestDataAttributesValue:
7091+
description: Types allowed for Reference Table row values.
7092+
oneOf:
7093+
- example: row_name
7094+
type: string
7095+
- example: 25
7096+
format: int32
7097+
maximum: 2147483647
7098+
type: integer
70917099
BillConfig:
70927100
description: Bill config.
70937101
properties:
@@ -79483,6 +79491,18 @@ paths:
7948379491
requestBody:
7948479492
content:
7948579493
application/json:
79494+
examples:
79495+
happy_path:
79496+
summary: Upsert a row with mixed string and int values
79497+
value:
79498+
data:
79499+
- attributes:
79500+
values:
79501+
age: 25
79502+
example_key_value: primary_key_value
79503+
name: row_name
79504+
id: primary_key_value
79505+
type: row
7948679506
schema:
7948779507
$ref: '#/components/schemas/BatchUpsertRowsRequestArray'
7948879508
required: true

api/datadogV2/model_batch_upsert_rows_request_data_attributes.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212

1313
// BatchUpsertRowsRequestDataAttributes Attributes containing row data values for row creation or update operations.
1414
type BatchUpsertRowsRequestDataAttributes struct {
15-
// Key-value pairs representing row data, where keys are field names from the schema.
16-
Values map[string]interface{} `json:"values"`
15+
// Key-value pairs representing row data, where keys are schema field names and values match the corresponding column types.
16+
Values map[string]BatchUpsertRowsRequestDataAttributesValue `json:"values"`
1717
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
1818
UnparsedObject map[string]interface{} `json:"-"`
1919
AdditionalProperties map[string]interface{} `json:"-"`
@@ -23,7 +23,7 @@ type BatchUpsertRowsRequestDataAttributes struct {
2323
// This constructor will assign default values to properties that have it defined,
2424
// and makes sure properties required by API are set, but the set of arguments
2525
// will change when the set of required properties is changed.
26-
func NewBatchUpsertRowsRequestDataAttributes(values map[string]interface{}) *BatchUpsertRowsRequestDataAttributes {
26+
func NewBatchUpsertRowsRequestDataAttributes(values map[string]BatchUpsertRowsRequestDataAttributesValue) *BatchUpsertRowsRequestDataAttributes {
2727
this := BatchUpsertRowsRequestDataAttributes{}
2828
this.Values = values
2929
return &this
@@ -38,25 +38,25 @@ func NewBatchUpsertRowsRequestDataAttributesWithDefaults() *BatchUpsertRowsReque
3838
}
3939

4040
// GetValues returns the Values field value.
41-
func (o *BatchUpsertRowsRequestDataAttributes) GetValues() map[string]interface{} {
41+
func (o *BatchUpsertRowsRequestDataAttributes) GetValues() map[string]BatchUpsertRowsRequestDataAttributesValue {
4242
if o == nil {
43-
var ret map[string]interface{}
43+
var ret map[string]BatchUpsertRowsRequestDataAttributesValue
4444
return ret
4545
}
4646
return o.Values
4747
}
4848

4949
// GetValuesOk returns a tuple with the Values field value
5050
// and a boolean to check if the value has been set.
51-
func (o *BatchUpsertRowsRequestDataAttributes) GetValuesOk() (*map[string]interface{}, bool) {
51+
func (o *BatchUpsertRowsRequestDataAttributes) GetValuesOk() (*map[string]BatchUpsertRowsRequestDataAttributesValue, bool) {
5252
if o == nil {
5353
return nil, false
5454
}
5555
return &o.Values, true
5656
}
5757

5858
// SetValues sets field value.
59-
func (o *BatchUpsertRowsRequestDataAttributes) SetValues(v map[string]interface{}) {
59+
func (o *BatchUpsertRowsRequestDataAttributes) SetValues(v map[string]BatchUpsertRowsRequestDataAttributesValue) {
6060
o.Values = v
6161
}
6262

@@ -77,7 +77,7 @@ func (o BatchUpsertRowsRequestDataAttributes) MarshalJSON() ([]byte, error) {
7777
// UnmarshalJSON deserializes the given payload.
7878
func (o *BatchUpsertRowsRequestDataAttributes) UnmarshalJSON(bytes []byte) (err error) {
7979
all := struct {
80-
Values *map[string]interface{} `json:"values"`
80+
Values *map[string]BatchUpsertRowsRequestDataAttributesValue `json:"values"`
8181
}{}
8282
if err = datadog.Unmarshal(bytes, &all); err != nil {
8383
return datadog.Unmarshal(bytes, &o.UnparsedObject)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
package datadogV2
6+
7+
import (
8+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
9+
)
10+
11+
// BatchUpsertRowsRequestDataAttributesValue - Types allowed for Reference Table row values.
12+
type BatchUpsertRowsRequestDataAttributesValue struct {
13+
String *string
14+
Int32 *int32
15+
16+
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
17+
UnparsedObject interface{}
18+
}
19+
20+
// StringAsBatchUpsertRowsRequestDataAttributesValue is a convenience function that returns string wrapped in BatchUpsertRowsRequestDataAttributesValue.
21+
func StringAsBatchUpsertRowsRequestDataAttributesValue(v *string) BatchUpsertRowsRequestDataAttributesValue {
22+
return BatchUpsertRowsRequestDataAttributesValue{String: v}
23+
}
24+
25+
// Int32AsBatchUpsertRowsRequestDataAttributesValue is a convenience function that returns int32 wrapped in BatchUpsertRowsRequestDataAttributesValue.
26+
func Int32AsBatchUpsertRowsRequestDataAttributesValue(v *int32) BatchUpsertRowsRequestDataAttributesValue {
27+
return BatchUpsertRowsRequestDataAttributesValue{Int32: v}
28+
}
29+
30+
// UnmarshalJSON turns data into one of the pointers in the struct.
31+
func (obj *BatchUpsertRowsRequestDataAttributesValue) UnmarshalJSON(data []byte) error {
32+
var err error
33+
match := 0
34+
// try to unmarshal data into String
35+
err = datadog.Unmarshal(data, &obj.String)
36+
if err == nil {
37+
if obj.String != nil {
38+
jsonString, _ := datadog.Marshal(obj.String)
39+
if string(jsonString) == "{}" { // empty struct
40+
obj.String = nil
41+
} else {
42+
match++
43+
}
44+
} else {
45+
obj.String = nil
46+
}
47+
} else {
48+
obj.String = nil
49+
}
50+
51+
// try to unmarshal data into Int32
52+
err = datadog.Unmarshal(data, &obj.Int32)
53+
if err == nil {
54+
if obj.Int32 != nil {
55+
jsonInt32, _ := datadog.Marshal(obj.Int32)
56+
if string(jsonInt32) == "{}" { // empty struct
57+
obj.Int32 = nil
58+
} else {
59+
match++
60+
}
61+
} else {
62+
obj.Int32 = nil
63+
}
64+
} else {
65+
obj.Int32 = nil
66+
}
67+
68+
if match != 1 { // more than 1 match
69+
// reset to nil
70+
obj.String = nil
71+
obj.Int32 = nil
72+
return datadog.Unmarshal(data, &obj.UnparsedObject)
73+
}
74+
return nil // exactly one match
75+
}
76+
77+
// MarshalJSON turns data from the first non-nil pointers in the struct to JSON.
78+
func (obj BatchUpsertRowsRequestDataAttributesValue) MarshalJSON() ([]byte, error) {
79+
if obj.String != nil {
80+
return datadog.Marshal(&obj.String)
81+
}
82+
83+
if obj.Int32 != nil {
84+
return datadog.Marshal(&obj.Int32)
85+
}
86+
87+
if obj.UnparsedObject != nil {
88+
return datadog.Marshal(obj.UnparsedObject)
89+
}
90+
return nil, nil // no data in oneOf schemas
91+
}
92+
93+
// GetActualInstance returns the actual instance.
94+
func (obj *BatchUpsertRowsRequestDataAttributesValue) GetActualInstance() interface{} {
95+
if obj.String != nil {
96+
return obj.String
97+
}
98+
99+
if obj.Int32 != nil {
100+
return obj.Int32
101+
}
102+
103+
// all schemas are nil
104+
return nil
105+
}

examples/v2/reference-tables/UpsertRows.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ func main() {
1616
Data: []datadogV2.BatchUpsertRowsRequestData{
1717
{
1818
Attributes: &datadogV2.BatchUpsertRowsRequestDataAttributes{
19-
Values: map[string]interface{}{
20-
"example_key_value": "primary_key_value",
21-
"name": "row_name",
22-
},
19+
Values: map[string]datadogV2.BatchUpsertRowsRequestDataAttributesValue{},
2320
},
2421
Id: "primary_key_value",
2522
Type: datadogV2.TABLEROWRESOURCEDATATYPE_ROW,

tests/scenarios/features/v2/reference_tables.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,22 @@ Feature: Reference Tables
148148
Scenario: Upsert rows returns "Bad Request" response
149149
Given new "UpsertRows" request
150150
And request contains "id" parameter from "REPLACE.ME"
151-
And body with value {"data": [{"attributes": {"values": {"example_key_value": "primary_key_value", "name": "row_name"}}, "id": "primary_key_value", "type": "row"}]}
151+
And body with value {"data": [{"attributes": {"values": {}}, "id": "primary_key_value", "type": "row"}]}
152152
When the request is sent
153153
Then the response status is 400 Bad Request
154154

155155
@generated @skip @team:DataDog/redapl-experiences
156156
Scenario: Upsert rows returns "Not Found" response
157157
Given new "UpsertRows" request
158158
And request contains "id" parameter from "REPLACE.ME"
159-
And body with value {"data": [{"attributes": {"values": {"example_key_value": "primary_key_value", "name": "row_name"}}, "id": "primary_key_value", "type": "row"}]}
159+
And body with value {"data": [{"attributes": {"values": {}}, "id": "primary_key_value", "type": "row"}]}
160160
When the request is sent
161161
Then the response status is 404 Not Found
162162

163163
@generated @skip @team:DataDog/redapl-experiences
164164
Scenario: Upsert rows returns "Rows created or updated successfully" response
165165
Given new "UpsertRows" request
166166
And request contains "id" parameter from "REPLACE.ME"
167-
And body with value {"data": [{"attributes": {"values": {"example_key_value": "primary_key_value", "name": "row_name"}}, "id": "primary_key_value", "type": "row"}]}
167+
And body with value {"data": [{"attributes": {"values": {}}, "id": "primary_key_value", "type": "row"}]}
168168
When the request is sent
169169
Then the response status is 200 Rows created or updated successfully

0 commit comments

Comments
 (0)