diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 6e4cbaacff9..aba68e52a57 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -6806,6 +6806,72 @@ components: required: - data type: object + BatchDeleteRowsRequestArray: + description: The request body for deleting multiple rows from a reference table. + properties: + data: + items: + $ref: '#/components/schemas/BatchDeleteRowsRequestData' + maxItems: 200 + type: array + required: + - data + type: object + BatchDeleteRowsRequestData: + description: Row resource containing a single row identifier for deletion. + properties: + id: + example: primary_key_value + type: string + type: + $ref: '#/components/schemas/TableRowResourceDataType' + required: + - type + - id + type: object + BatchUpsertRowsRequestArray: + description: The request body for creating or updating multiple rows into a + reference table. + properties: + data: + items: + $ref: '#/components/schemas/BatchUpsertRowsRequestData' + maxItems: 200 + type: array + required: + - data + type: object + BatchUpsertRowsRequestData: + description: Row resource containing a single row identifier and its column + values. + properties: + attributes: + $ref: '#/components/schemas/BatchUpsertRowsRequestDataAttributes' + id: + example: primary_key_value + type: string + type: + $ref: '#/components/schemas/TableRowResourceDataType' + required: + - type + - id + type: object + BatchUpsertRowsRequestDataAttributes: + description: Attributes containing row data values for row creation or update + operations. + properties: + values: + additionalProperties: + x-required-field: true + description: Key-value pairs representing row data, where keys are field + names from the schema. + example: + example_key_value: primary_key_value + name: row_name + type: object + required: + - values + type: object BillConfig: description: Bill config. properties: @@ -74549,6 +74615,47 @@ paths: tags: - Reference Tables /api/v2/reference-tables/tables/{id}/rows: + delete: + description: Delete multiple rows from a Reference Table by their primary key + values. + operationId: DeleteRows + parameters: + - description: Unique identifier of the reference table to delete rows from + in: path + name: id + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/BatchDeleteRowsRequestArray' + required: true + responses: + '200': + description: Rows deleted successfully + '400': + $ref: '#/components/responses/BadRequestResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + '500': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Internal Server Error + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] + summary: Delete rows + tags: + - Reference Tables get: description: Get reference table rows by their primary key values. operationId: GetRowsByID @@ -74593,6 +74700,48 @@ paths: summary: Get rows by id tags: - Reference Tables + post: + description: Create or update rows in a Reference Table by their primary key + values. If a row with the specified primary key exists, it is updated; otherwise, + a new row is created. + operationId: UpsertRows + parameters: + - description: Unique identifier of the reference table to upsert rows into + in: path + name: id + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/BatchUpsertRowsRequestArray' + required: true + responses: + '200': + description: Rows created or updated successfully + '400': + $ref: '#/components/responses/BadRequestResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + '500': + content: + application/json: + schema: + $ref: '#/components/schemas/APIErrorResponse' + description: Internal Server Error + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: [] + summary: Upsert rows + tags: + - Reference Tables /api/v2/reference-tables/uploads: post: description: Create a reference table upload for bulk data ingestion diff --git a/api/datadogV2/api_reference_tables.go b/api/datadogV2/api_reference_tables.go index 4df62723b34..5d6e43bd292 100644 --- a/api/datadogV2/api_reference_tables.go +++ b/api/datadogV2/api_reference_tables.go @@ -180,6 +180,77 @@ func (a *ReferenceTablesApi) CreateReferenceTableUpload(ctx _context.Context, bo return localVarReturnValue, localVarHTTPResponse, nil } +// DeleteRows Delete rows. +// Delete multiple rows from a Reference Table by their primary key values. +func (a *ReferenceTablesApi) DeleteRows(ctx _context.Context, id string, body BatchDeleteRowsRequestArray) (*_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodDelete + localVarPostBody interface{} + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.ReferenceTablesApi.DeleteRows") + if err != nil { + return nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/reference-tables/tables/{id}/rows" + localVarPath = datadog.ReplacePathParameter(localVarPath, "{id}", _neturl.PathEscape(datadog.ParameterToString(id, ""))) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Content-Type"] = "application/json" + localVarHeaderParams["Accept"] = "*/*" + + // body params + localVarPostBody = &body + if a.Client.Cfg.DelegatedTokenConfig != nil { + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) + if err != nil { + return nil, err + } + } else { + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + } + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 || localVarHTTPResponse.StatusCode == 500 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + // DeleteTable Delete table. // Delete a reference table by ID func (a *ReferenceTablesApi) DeleteTable(ctx _context.Context, id string) (*_nethttp.Response, error) { @@ -639,6 +710,77 @@ func (a *ReferenceTablesApi) UpdateReferenceTable(ctx _context.Context, id strin return localVarHTTPResponse, nil } +// UpsertRows Upsert rows. +// Create or update rows in a Reference Table by their primary key values. If a row with the specified primary key exists, it is updated; otherwise, a new row is created. +func (a *ReferenceTablesApi) UpsertRows(ctx _context.Context, id string, body BatchUpsertRowsRequestArray) (*_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + ) + + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.ReferenceTablesApi.UpsertRows") + if err != nil { + return nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/reference-tables/tables/{id}/rows" + localVarPath = datadog.ReplacePathParameter(localVarPath, "{id}", _neturl.PathEscape(datadog.ParameterToString(id, ""))) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + localVarHeaderParams["Content-Type"] = "application/json" + localVarHeaderParams["Accept"] = "*/*" + + // body params + localVarPostBody = &body + if a.Client.Cfg.DelegatedTokenConfig != nil { + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) + if err != nil { + return nil, err + } + } else { + datadog.SetAuthKeys( + ctx, + &localVarHeaderParams, + [2]string{"apiKeyAuth", "DD-API-KEY"}, + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, + ) + } + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.Client.CallAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := datadog.GenericOpenAPIError{ + ErrorBody: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 || localVarHTTPResponse.StatusCode == 500 { + var v APIErrorResponse + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + return localVarHTTPResponse, newErr + } + newErr.ErrorModel = v + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + // NewReferenceTablesApi Returns NewReferenceTablesApi. func NewReferenceTablesApi(client *datadog.APIClient) *ReferenceTablesApi { return &ReferenceTablesApi{ diff --git a/api/datadogV2/doc.go b/api/datadogV2/doc.go index c5cf4723b97..345c167ee4c 100644 --- a/api/datadogV2/doc.go +++ b/api/datadogV2/doc.go @@ -465,11 +465,13 @@ // - [RUMApi.UpdateRUMApplication] // - [ReferenceTablesApi.CreateReferenceTable] // - [ReferenceTablesApi.CreateReferenceTableUpload] +// - [ReferenceTablesApi.DeleteRows] // - [ReferenceTablesApi.DeleteTable] // - [ReferenceTablesApi.GetRowsByID] // - [ReferenceTablesApi.GetTable] // - [ReferenceTablesApi.ListTables] // - [ReferenceTablesApi.UpdateReferenceTable] +// - [ReferenceTablesApi.UpsertRows] // - [RestrictionPoliciesApi.DeleteRestrictionPolicy] // - [RestrictionPoliciesApi.GetRestrictionPolicy] // - [RestrictionPoliciesApi.UpdateRestrictionPolicy] diff --git a/api/datadogV2/model_batch_delete_rows_request_array.go b/api/datadogV2/model_batch_delete_rows_request_array.go new file mode 100644 index 00000000000..78a6cb77107 --- /dev/null +++ b/api/datadogV2/model_batch_delete_rows_request_array.go @@ -0,0 +1,101 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// BatchDeleteRowsRequestArray The request body for deleting multiple rows from a reference table. +type BatchDeleteRowsRequestArray struct { + // + Data []BatchDeleteRowsRequestData `json:"data"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewBatchDeleteRowsRequestArray instantiates a new BatchDeleteRowsRequestArray object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewBatchDeleteRowsRequestArray(data []BatchDeleteRowsRequestData) *BatchDeleteRowsRequestArray { + this := BatchDeleteRowsRequestArray{} + this.Data = data + return &this +} + +// NewBatchDeleteRowsRequestArrayWithDefaults instantiates a new BatchDeleteRowsRequestArray object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewBatchDeleteRowsRequestArrayWithDefaults() *BatchDeleteRowsRequestArray { + this := BatchDeleteRowsRequestArray{} + return &this +} + +// GetData returns the Data field value. +func (o *BatchDeleteRowsRequestArray) GetData() []BatchDeleteRowsRequestData { + if o == nil { + var ret []BatchDeleteRowsRequestData + return ret + } + return o.Data +} + +// GetDataOk returns a tuple with the Data field value +// and a boolean to check if the value has been set. +func (o *BatchDeleteRowsRequestArray) GetDataOk() (*[]BatchDeleteRowsRequestData, bool) { + if o == nil { + return nil, false + } + return &o.Data, true +} + +// SetData sets field value. +func (o *BatchDeleteRowsRequestArray) SetData(v []BatchDeleteRowsRequestData) { + o.Data = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o BatchDeleteRowsRequestArray) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["data"] = o.Data + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *BatchDeleteRowsRequestArray) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *[]BatchDeleteRowsRequestData `json:"data"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Data == nil { + return fmt.Errorf("required field data missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + o.Data = *all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_batch_delete_rows_request_data.go b/api/datadogV2/model_batch_delete_rows_request_data.go new file mode 100644 index 00000000000..aec7ae8a5bd --- /dev/null +++ b/api/datadogV2/model_batch_delete_rows_request_data.go @@ -0,0 +1,145 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// BatchDeleteRowsRequestData Row resource containing a single row identifier for deletion. +type BatchDeleteRowsRequestData struct { + // + Id string `json:"id"` + // Row resource type. + Type TableRowResourceDataType `json:"type"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewBatchDeleteRowsRequestData instantiates a new BatchDeleteRowsRequestData object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewBatchDeleteRowsRequestData(id string, typeVar TableRowResourceDataType) *BatchDeleteRowsRequestData { + this := BatchDeleteRowsRequestData{} + this.Id = id + this.Type = typeVar + return &this +} + +// NewBatchDeleteRowsRequestDataWithDefaults instantiates a new BatchDeleteRowsRequestData object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewBatchDeleteRowsRequestDataWithDefaults() *BatchDeleteRowsRequestData { + this := BatchDeleteRowsRequestData{} + var typeVar TableRowResourceDataType = TABLEROWRESOURCEDATATYPE_ROW + this.Type = typeVar + return &this +} + +// GetId returns the Id field value. +func (o *BatchDeleteRowsRequestData) GetId() string { + if o == nil { + var ret string + return ret + } + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *BatchDeleteRowsRequestData) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value. +func (o *BatchDeleteRowsRequestData) SetId(v string) { + o.Id = v +} + +// GetType returns the Type field value. +func (o *BatchDeleteRowsRequestData) GetType() TableRowResourceDataType { + if o == nil { + var ret TableRowResourceDataType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *BatchDeleteRowsRequestData) GetTypeOk() (*TableRowResourceDataType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *BatchDeleteRowsRequestData) SetType(v TableRowResourceDataType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o BatchDeleteRowsRequestData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["id"] = o.Id + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *BatchDeleteRowsRequestData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Id *string `json:"id"` + Type *TableRowResourceDataType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Id == nil { + return fmt.Errorf("required field id missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"id", "type"}) + } else { + return err + } + + hasInvalidField := false + o.Id = *all.Id + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_batch_upsert_rows_request_array.go b/api/datadogV2/model_batch_upsert_rows_request_array.go new file mode 100644 index 00000000000..8af28e48f9a --- /dev/null +++ b/api/datadogV2/model_batch_upsert_rows_request_array.go @@ -0,0 +1,101 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// BatchUpsertRowsRequestArray The request body for creating or updating multiple rows into a reference table. +type BatchUpsertRowsRequestArray struct { + // + Data []BatchUpsertRowsRequestData `json:"data"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewBatchUpsertRowsRequestArray instantiates a new BatchUpsertRowsRequestArray object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewBatchUpsertRowsRequestArray(data []BatchUpsertRowsRequestData) *BatchUpsertRowsRequestArray { + this := BatchUpsertRowsRequestArray{} + this.Data = data + return &this +} + +// NewBatchUpsertRowsRequestArrayWithDefaults instantiates a new BatchUpsertRowsRequestArray object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewBatchUpsertRowsRequestArrayWithDefaults() *BatchUpsertRowsRequestArray { + this := BatchUpsertRowsRequestArray{} + return &this +} + +// GetData returns the Data field value. +func (o *BatchUpsertRowsRequestArray) GetData() []BatchUpsertRowsRequestData { + if o == nil { + var ret []BatchUpsertRowsRequestData + return ret + } + return o.Data +} + +// GetDataOk returns a tuple with the Data field value +// and a boolean to check if the value has been set. +func (o *BatchUpsertRowsRequestArray) GetDataOk() (*[]BatchUpsertRowsRequestData, bool) { + if o == nil { + return nil, false + } + return &o.Data, true +} + +// SetData sets field value. +func (o *BatchUpsertRowsRequestArray) SetData(v []BatchUpsertRowsRequestData) { + o.Data = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o BatchUpsertRowsRequestArray) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["data"] = o.Data + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *BatchUpsertRowsRequestArray) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Data *[]BatchUpsertRowsRequestData `json:"data"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Data == nil { + return fmt.Errorf("required field data missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"data"}) + } else { + return err + } + o.Data = *all.Data + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/api/datadogV2/model_batch_upsert_rows_request_data.go b/api/datadogV2/model_batch_upsert_rows_request_data.go new file mode 100644 index 00000000000..e883f7f52a1 --- /dev/null +++ b/api/datadogV2/model_batch_upsert_rows_request_data.go @@ -0,0 +1,183 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// BatchUpsertRowsRequestData Row resource containing a single row identifier and its column values. +type BatchUpsertRowsRequestData struct { + // Attributes containing row data values for row creation or update operations. + Attributes *BatchUpsertRowsRequestDataAttributes `json:"attributes,omitempty"` + // + Id string `json:"id"` + // Row resource type. + Type TableRowResourceDataType `json:"type"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewBatchUpsertRowsRequestData instantiates a new BatchUpsertRowsRequestData object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewBatchUpsertRowsRequestData(id string, typeVar TableRowResourceDataType) *BatchUpsertRowsRequestData { + this := BatchUpsertRowsRequestData{} + this.Id = id + this.Type = typeVar + return &this +} + +// NewBatchUpsertRowsRequestDataWithDefaults instantiates a new BatchUpsertRowsRequestData object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewBatchUpsertRowsRequestDataWithDefaults() *BatchUpsertRowsRequestData { + this := BatchUpsertRowsRequestData{} + var typeVar TableRowResourceDataType = TABLEROWRESOURCEDATATYPE_ROW + this.Type = typeVar + return &this +} + +// GetAttributes returns the Attributes field value if set, zero value otherwise. +func (o *BatchUpsertRowsRequestData) GetAttributes() BatchUpsertRowsRequestDataAttributes { + if o == nil || o.Attributes == nil { + var ret BatchUpsertRowsRequestDataAttributes + return ret + } + return *o.Attributes +} + +// GetAttributesOk returns a tuple with the Attributes field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *BatchUpsertRowsRequestData) GetAttributesOk() (*BatchUpsertRowsRequestDataAttributes, bool) { + if o == nil || o.Attributes == nil { + return nil, false + } + return o.Attributes, true +} + +// HasAttributes returns a boolean if a field has been set. +func (o *BatchUpsertRowsRequestData) HasAttributes() bool { + return o != nil && o.Attributes != nil +} + +// SetAttributes gets a reference to the given BatchUpsertRowsRequestDataAttributes and assigns it to the Attributes field. +func (o *BatchUpsertRowsRequestData) SetAttributes(v BatchUpsertRowsRequestDataAttributes) { + o.Attributes = &v +} + +// GetId returns the Id field value. +func (o *BatchUpsertRowsRequestData) GetId() string { + if o == nil { + var ret string + return ret + } + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *BatchUpsertRowsRequestData) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value. +func (o *BatchUpsertRowsRequestData) SetId(v string) { + o.Id = v +} + +// GetType returns the Type field value. +func (o *BatchUpsertRowsRequestData) GetType() TableRowResourceDataType { + if o == nil { + var ret TableRowResourceDataType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *BatchUpsertRowsRequestData) GetTypeOk() (*TableRowResourceDataType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *BatchUpsertRowsRequestData) SetType(v TableRowResourceDataType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o BatchUpsertRowsRequestData) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + if o.Attributes != nil { + toSerialize["attributes"] = o.Attributes + } + toSerialize["id"] = o.Id + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *BatchUpsertRowsRequestData) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Attributes *BatchUpsertRowsRequestDataAttributes `json:"attributes,omitempty"` + Id *string `json:"id"` + Type *TableRowResourceDataType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Id == nil { + return fmt.Errorf("required field id missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"attributes", "id", "type"}) + } else { + return err + } + + hasInvalidField := false + if all.Attributes != nil && all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Attributes = all.Attributes + o.Id = *all.Id + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV2/model_batch_upsert_rows_request_data_attributes.go b/api/datadogV2/model_batch_upsert_rows_request_data_attributes.go new file mode 100644 index 00000000000..7501c961b58 --- /dev/null +++ b/api/datadogV2/model_batch_upsert_rows_request_data_attributes.go @@ -0,0 +1,101 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +package datadogV2 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// BatchUpsertRowsRequestDataAttributes Attributes containing row data values for row creation or update operations. +type BatchUpsertRowsRequestDataAttributes struct { + // Key-value pairs representing row data, where keys are field names from the schema. + Values map[string]interface{} `json:"values"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewBatchUpsertRowsRequestDataAttributes instantiates a new BatchUpsertRowsRequestDataAttributes object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewBatchUpsertRowsRequestDataAttributes(values map[string]interface{}) *BatchUpsertRowsRequestDataAttributes { + this := BatchUpsertRowsRequestDataAttributes{} + this.Values = values + return &this +} + +// NewBatchUpsertRowsRequestDataAttributesWithDefaults instantiates a new BatchUpsertRowsRequestDataAttributes object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewBatchUpsertRowsRequestDataAttributesWithDefaults() *BatchUpsertRowsRequestDataAttributes { + this := BatchUpsertRowsRequestDataAttributes{} + return &this +} + +// GetValues returns the Values field value. +func (o *BatchUpsertRowsRequestDataAttributes) GetValues() map[string]interface{} { + if o == nil { + var ret map[string]interface{} + return ret + } + return o.Values +} + +// GetValuesOk returns a tuple with the Values field value +// and a boolean to check if the value has been set. +func (o *BatchUpsertRowsRequestDataAttributes) GetValuesOk() (*map[string]interface{}, bool) { + if o == nil { + return nil, false + } + return &o.Values, true +} + +// SetValues sets field value. +func (o *BatchUpsertRowsRequestDataAttributes) SetValues(v map[string]interface{}) { + o.Values = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o BatchUpsertRowsRequestDataAttributes) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["values"] = o.Values + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *BatchUpsertRowsRequestDataAttributes) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Values *map[string]interface{} `json:"values"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Values == nil { + return fmt.Errorf("required field values missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"values"}) + } else { + return err + } + o.Values = *all.Values + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + return nil +} diff --git a/examples/v2/reference-tables/DeleteRows.go b/examples/v2/reference-tables/DeleteRows.go new file mode 100644 index 00000000000..71ae70086e4 --- /dev/null +++ b/examples/v2/reference-tables/DeleteRows.go @@ -0,0 +1,33 @@ +// Delete rows returns "Rows deleted successfully" response + +package main + +import ( + "context" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + body := datadogV2.BatchDeleteRowsRequestArray{ + Data: []datadogV2.BatchDeleteRowsRequestData{ + { + Id: "primary_key_value", + Type: datadogV2.TABLEROWRESOURCEDATATYPE_ROW, + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewReferenceTablesApi(apiClient) + r, err := api.DeleteRows(ctx, "id", body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ReferenceTablesApi.DeleteRows`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } +} diff --git a/examples/v2/reference-tables/UpsertRows.go b/examples/v2/reference-tables/UpsertRows.go new file mode 100644 index 00000000000..e0b7f91cdf4 --- /dev/null +++ b/examples/v2/reference-tables/UpsertRows.go @@ -0,0 +1,39 @@ +// Upsert rows returns "Rows created or updated successfully" response + +package main + +import ( + "context" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" +) + +func main() { + body := datadogV2.BatchUpsertRowsRequestArray{ + Data: []datadogV2.BatchUpsertRowsRequestData{ + { + Attributes: &datadogV2.BatchUpsertRowsRequestDataAttributes{ + Values: map[string]interface{}{ + "example_key_value": "primary_key_value", + "name": "row_name", + }, + }, + Id: "primary_key_value", + Type: datadogV2.TABLEROWRESOURCEDATATYPE_ROW, + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV2.NewReferenceTablesApi(apiClient) + r, err := api.UpsertRows(ctx, "id", body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ReferenceTablesApi.UpsertRows`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } +} diff --git a/tests/scenarios/features/v2/reference_tables.feature b/tests/scenarios/features/v2/reference_tables.feature index fa3ea42360a..45a2861c15b 100644 --- a/tests/scenarios/features/v2/reference_tables.feature +++ b/tests/scenarios/features/v2/reference_tables.feature @@ -53,6 +53,30 @@ Feature: Reference Tables When the request is sent Then the response status is 400 Bad Request + @generated @skip @team:DataDog/redapl-experiences + Scenario: Delete rows returns "Bad Request" response + Given new "DeleteRows" request + And request contains "id" parameter from "REPLACE.ME" + And body with value {"data": [{"id": "primary_key_value", "type": "row"}]} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/redapl-experiences + Scenario: Delete rows returns "Not Found" response + Given new "DeleteRows" request + And request contains "id" parameter from "REPLACE.ME" + And body with value {"data": [{"id": "primary_key_value", "type": "row"}]} + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/redapl-experiences + Scenario: Delete rows returns "Rows deleted successfully" response + Given new "DeleteRows" request + And request contains "id" parameter from "REPLACE.ME" + And body with value {"data": [{"id": "primary_key_value", "type": "row"}]} + When the request is sent + Then the response status is 200 Rows deleted successfully + @generated @skip @team:DataDog/redapl-experiences Scenario: Delete table returns "Not Found" response Given new "DeleteTable" request @@ -119,3 +143,27 @@ Feature: Reference Tables And body with value {"data": {"attributes": {"description": "this is a cloud table generated via a cloud bucket sync", "file_metadata": {"access_details": {"aws_detail": {"aws_account_id": "test-account-id", "aws_bucket_name": "test-bucket", "file_path": "test_rt.csv"}}, "sync_enabled": true}, "schema": {"fields": [{"name": "id", "type": "INT32"}, {"name": "name", "type": "STRING"}], "primary_keys": ["id"]}, "sync_enabled": false, "tags": ["test_tag"]}, "type": "reference_table"}} When the request is sent Then the response status is 200 OK + + @generated @skip @team:DataDog/redapl-experiences + Scenario: Upsert rows returns "Bad Request" response + Given new "UpsertRows" request + And request contains "id" parameter from "REPLACE.ME" + And body with value {"data": [{"attributes": {"values": {"example_key_value": "primary_key_value", "name": "row_name"}}, "id": "primary_key_value", "type": "row"}]} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/redapl-experiences + Scenario: Upsert rows returns "Not Found" response + Given new "UpsertRows" request + And request contains "id" parameter from "REPLACE.ME" + And body with value {"data": [{"attributes": {"values": {"example_key_value": "primary_key_value", "name": "row_name"}}, "id": "primary_key_value", "type": "row"}]} + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/redapl-experiences + Scenario: Upsert rows returns "Rows created or updated successfully" response + Given new "UpsertRows" request + And request contains "id" parameter from "REPLACE.ME" + And body with value {"data": [{"attributes": {"values": {"example_key_value": "primary_key_value", "name": "row_name"}}, "id": "primary_key_value", "type": "row"}]} + When the request is sent + Then the response status is 200 Rows created or updated successfully diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index 3799e64e630..35580ed3fcd 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -3089,12 +3089,26 @@ "type": "idempotent" } }, + "DeleteRows": { + "tag": "Reference Tables", + "undo": { + "type": "idempotent" + } + }, "GetRowsByID": { "tag": "Reference Tables", "undo": { "type": "safe" } }, + "UpsertRows": { + "tag": "Reference Tables", + "undo": { + "operationId": "DeleteRows", + "parameters": [], + "type": "unsafe" + } + }, "CreateReferenceTableUpload": { "tag": "Reference Tables", "undo": {