Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions examples/v2_reference-tables_UpsertRows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/datadogV2/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, serde_json::Value>,
pub values: std::collections::BTreeMap<
String,
crate::datadogV2::model::BatchUpsertRowsRequestDataAttributesValue,
>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
Expand All @@ -23,7 +26,10 @@ pub struct BatchUpsertRowsRequestDataAttributes {

impl BatchUpsertRowsRequestDataAttributes {
pub fn new(
values: std::collections::BTreeMap<String, serde_json::Value>,
values: std::collections::BTreeMap<
String,
crate::datadogV2::model::BatchUpsertRowsRequestDataAttributesValue,
>,
) -> BatchUpsertRowsRequestDataAttributes {
BatchUpsertRowsRequestDataAttributes {
values,
Expand Down Expand Up @@ -58,8 +64,12 @@ impl<'de> Deserialize<'de> for BatchUpsertRowsRequestDataAttributes {
where
M: MapAccess<'a>,
{
let mut values: Option<std::collections::BTreeMap<String, serde_json::Value>> =
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let value: serde_json::Value = Deserialize::deserialize(deserializer)?;
if let Ok(_v) = serde_json::from_value::<String>(value.clone()) {
return Ok(BatchUpsertRowsRequestDataAttributesValue::String(_v));
}
if let Ok(_v) = serde_json::from_value::<i32>(value.clone()) {
return Ok(BatchUpsertRowsRequestDataAttributesValue::I32(_v));
}

return Ok(BatchUpsertRowsRequestDataAttributesValue::UnparsedObject(
crate::datadog::UnparsedObject { value },
));
}
}
6 changes: 3 additions & 3 deletions tests/scenarios/features/v2/reference_tables.feature
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,22 @@ 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

@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"}]}
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

@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"}]}
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