diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index a4628b43a..e14e4a498 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.rs b/examples/v2_reference-tables_UpsertRows.rs index 86787ba8d..2eb719ceb 100644 --- a/examples/v2_reference-tables_UpsertRows.rs +++ b/examples/v2_reference-tables_UpsertRows.rs @@ -5,7 +5,6 @@ use datadog_api_client::datadogV2::model::BatchUpsertRowsRequestArray; use datadog_api_client::datadogV2::model::BatchUpsertRowsRequestData; use datadog_api_client::datadogV2::model::BatchUpsertRowsRequestDataAttributes; use datadog_api_client::datadogV2::model::TableRowResourceDataType; -use serde_json::Value; use std::collections::BTreeMap; #[tokio::main] @@ -14,13 +13,9 @@ async fn main() { "primary_key_value".to_string(), TableRowResourceDataType::ROW, ) - .attributes(BatchUpsertRowsRequestDataAttributes::new(BTreeMap::from([ - ( - "example_key_value".to_string(), - Value::from("primary_key_value"), - ), - ("name".to_string(), Value::from("row_name")), - ])))]); + .attributes(BatchUpsertRowsRequestDataAttributes::new( + BTreeMap::from([]), + ))]); let configuration = datadog::Configuration::new(); let api = ReferenceTablesAPI::with_config(configuration); let resp = api.upsert_rows("id".to_string(), body).await; diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index d52ce9191..700fb7b28 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -4872,6 +4872,8 @@ pub mod model_batch_upsert_rows_request_data; pub use self::model_batch_upsert_rows_request_data::BatchUpsertRowsRequestData; pub mod model_batch_upsert_rows_request_data_attributes; pub use self::model_batch_upsert_rows_request_data_attributes::BatchUpsertRowsRequestDataAttributes; +pub mod model_batch_upsert_rows_request_data_attributes_value; +pub use self::model_batch_upsert_rows_request_data_attributes_value::BatchUpsertRowsRequestDataAttributesValue; pub mod model_create_upload_request; pub use self::model_create_upload_request::CreateUploadRequest; pub mod model_create_upload_request_data; diff --git a/src/datadogV2/model/model_batch_upsert_rows_request_data_attributes.rs b/src/datadogV2/model/model_batch_upsert_rows_request_data_attributes.rs index 2bba778da..8d6aafdc3 100644 --- a/src/datadogV2/model/model_batch_upsert_rows_request_data_attributes.rs +++ b/src/datadogV2/model/model_batch_upsert_rows_request_data_attributes.rs @@ -11,9 +11,12 @@ use std::fmt::{self, Formatter}; #[skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize)] pub struct BatchUpsertRowsRequestDataAttributes { - /// 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. #[serde(rename = "values")] - pub values: std::collections::BTreeMap, + pub values: std::collections::BTreeMap< + String, + crate::datadogV2::model::BatchUpsertRowsRequestDataAttributesValue, + >, #[serde(flatten)] pub additional_properties: std::collections::BTreeMap, #[serde(skip)] @@ -23,7 +26,10 @@ pub struct BatchUpsertRowsRequestDataAttributes { impl BatchUpsertRowsRequestDataAttributes { pub fn new( - values: std::collections::BTreeMap, + values: std::collections::BTreeMap< + String, + crate::datadogV2::model::BatchUpsertRowsRequestDataAttributesValue, + >, ) -> BatchUpsertRowsRequestDataAttributes { BatchUpsertRowsRequestDataAttributes { values, @@ -58,8 +64,12 @@ impl<'de> Deserialize<'de> for BatchUpsertRowsRequestDataAttributes { where M: MapAccess<'a>, { - let mut values: Option> = - None; + let mut values: Option< + std::collections::BTreeMap< + String, + crate::datadogV2::model::BatchUpsertRowsRequestDataAttributesValue, + >, + > = None; let mut additional_properties: std::collections::BTreeMap< String, serde_json::Value, diff --git a/src/datadogV2/model/model_batch_upsert_rows_request_data_attributes_value.rs b/src/datadogV2/model/model_batch_upsert_rows_request_data_attributes_value.rs new file mode 100644 index 000000000..33c5d96b3 --- /dev/null +++ b/src/datadogV2/model/model_batch_upsert_rows_request_data_attributes_value.rs @@ -0,0 +1,33 @@ +// 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. +use serde::{Deserialize, Deserializer, Serialize}; + +/// Types allowed for Reference Table row values. +#[non_exhaustive] +#[derive(Clone, Debug, PartialEq, Serialize)] +#[serde(untagged)] +pub enum BatchUpsertRowsRequestDataAttributesValue { + String(String), + I32(i32), + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl<'de> Deserialize<'de> for BatchUpsertRowsRequestDataAttributesValue { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let value: serde_json::Value = Deserialize::deserialize(deserializer)?; + if let Ok(_v) = serde_json::from_value::(value.clone()) { + return Ok(BatchUpsertRowsRequestDataAttributesValue::String(_v)); + } + if let Ok(_v) = serde_json::from_value::(value.clone()) { + return Ok(BatchUpsertRowsRequestDataAttributesValue::I32(_v)); + } + + return Ok(BatchUpsertRowsRequestDataAttributesValue::UnparsedObject( + crate::datadog::UnparsedObject { value }, + )); + } +} diff --git a/tests/scenarios/features/v2/reference_tables.feature b/tests/scenarios/features/v2/reference_tables.feature index 45a2861c1..230be9e8f 100644 --- a/tests/scenarios/features/v2/reference_tables.feature +++ b/tests/scenarios/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