diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index a4628b43a715..e14e4a498bb4 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -7075,19 +7075,27 @@ components: BatchUpsertRowsRequestDataAttributes: description: Attributes containing row data values for row creation or update operations. + example: + values: {} 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 + $ref: '#/components/schemas/BatchUpsertRowsRequestDataAttributesValue' + description: Key-value pairs representing row data, where keys are schema + field names and values match the corresponding column types. type: object required: - values type: object + BatchUpsertRowsRequestDataAttributesValue: + description: Types allowed for Reference Table row values. + oneOf: + - example: row_name + type: string + - example: 25 + format: int32 + maximum: 2147483647 + type: integer BillConfig: description: Bill config. properties: @@ -79331,6 +79339,18 @@ paths: requestBody: content: application/json: + examples: + happy_path: + summary: Upsert a row with mixed string and int values + value: + data: + - attributes: + values: + age: 25 + example_key_value: primary_key_value + name: row_name + id: primary_key_value + type: row schema: $ref: '#/components/schemas/BatchUpsertRowsRequestArray' required: true diff --git a/examples/v2/reference-tables/UpsertRows.rb b/examples/v2/reference-tables/UpsertRows.rb index 2be0aa5d10a5..4e39959454b0 100644 --- a/examples/v2/reference-tables/UpsertRows.rb +++ b/examples/v2/reference-tables/UpsertRows.rb @@ -7,9 +7,7 @@ data: [ DatadogAPIClient::V2::BatchUpsertRowsRequestData.new({ attributes: DatadogAPIClient::V2::BatchUpsertRowsRequestDataAttributes.new({ - values: { - example_key_value: "primary_key_value", name: "row_name", - }, + values: {}, }), id: "primary_key_value", type: DatadogAPIClient::V2::TableRowResourceDataType::ROW, diff --git a/features/v2/reference_tables.feature b/features/v2/reference_tables.feature index 45a2861c15b5..230be9e8f4d8 100644 --- a/features/v2/reference_tables.feature +++ b/features/v2/reference_tables.feature @@ -148,7 +148,7 @@ Feature: Reference Tables 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"}]} + And body with value {"data": [{"attributes": {"values": {}}, "id": "primary_key_value", "type": "row"}]} When the request is sent Then the response status is 400 Bad Request @@ -156,7 +156,7 @@ Feature: Reference Tables 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"}]} + And body with value {"data": [{"attributes": {"values": {}}, "id": "primary_key_value", "type": "row"}]} When the request is sent Then the response status is 404 Not Found @@ -164,6 +164,6 @@ Feature: Reference Tables 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"}]} + And body with value {"data": [{"attributes": {"values": {}}, "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/lib/datadog_api_client/inflector.rb b/lib/datadog_api_client/inflector.rb index a6c91f777c4e..aba1e8975df0 100644 --- a/lib/datadog_api_client/inflector.rb +++ b/lib/datadog_api_client/inflector.rb @@ -1334,6 +1334,7 @@ def overrides "v2.batch_upsert_rows_request_array" => "BatchUpsertRowsRequestArray", "v2.batch_upsert_rows_request_data" => "BatchUpsertRowsRequestData", "v2.batch_upsert_rows_request_data_attributes" => "BatchUpsertRowsRequestDataAttributes", + "v2.batch_upsert_rows_request_data_attributes_value" => "BatchUpsertRowsRequestDataAttributesValue", "v2.bill_config" => "BillConfig", "v2.billing_dimensions_mapping_body_item" => "BillingDimensionsMappingBodyItem", "v2.billing_dimensions_mapping_body_item_attributes" => "BillingDimensionsMappingBodyItemAttributes", diff --git a/lib/datadog_api_client/v2/models/batch_upsert_rows_request_data_attributes.rb b/lib/datadog_api_client/v2/models/batch_upsert_rows_request_data_attributes.rb index e98f807a8b93..41ba13e47bb1 100644 --- a/lib/datadog_api_client/v2/models/batch_upsert_rows_request_data_attributes.rb +++ b/lib/datadog_api_client/v2/models/batch_upsert_rows_request_data_attributes.rb @@ -21,7 +21,7 @@ module DatadogAPIClient::V2 class BatchUpsertRowsRequestDataAttributes include BaseGenericModel - # Key-value pairs representing row data, where keys are field names from the schema. + # Key-value pairs representing row data, where keys are schema field names and values match the corresponding column types. attr_reader :values attr_accessor :additional_properties @@ -38,7 +38,7 @@ def self.attribute_map # @!visibility private def self.openapi_types { - :'values' => :'Hash' + :'values' => :'Hash' } end diff --git a/lib/datadog_api_client/v2/models/batch_upsert_rows_request_data_attributes_value.rb b/lib/datadog_api_client/v2/models/batch_upsert_rows_request_data_attributes_value.rb new file mode 100644 index 000000000000..a43714c106cc --- /dev/null +++ b/lib/datadog_api_client/v2/models/batch_upsert_rows_request_data_attributes_value.rb @@ -0,0 +1,63 @@ +=begin +#Datadog API V2 Collection + +#Collection of all Datadog Public endpoints. + +The version of the OpenAPI document: 1.0 +Contact: support@datadoghq.com +Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator + + 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 2020-Present Datadog, Inc. + +=end + +require 'date' +require 'time' + +module DatadogAPIClient::V2 + # Types allowed for Reference Table row values. + module BatchUpsertRowsRequestDataAttributesValue + class << self + include BaseOneOfModel + include BaseOneOfModelNoDiscriminator + + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :'String', + :'Integer' + ] + end + # Builds the object + # @param data [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + next if klass == :AnyType # "nullable: true" + typed_data = find_and_cast_into_type(klass, data) + next if typed_data.respond_to?(:_unparsed) && typed_data._unparsed + return typed_data if typed_data + rescue # rescue all errors so we keep iterating even if the current item lookup raises + end + end + + if openapi_one_of.include?(:AnyType) + data + else + self._unparsed = true + DatadogAPIClient::UnparsedObject.new(data) + end + end + end + end +end