diff --git a/.apigentools-info b/.apigentools-info index 8f172aba5..ff6d007f7 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-10-02 14:33:54.593908", - "spec_repo_commit": "3b4747f4" + "regenerated": "2024-10-02 16:22:32.655426", + "spec_repo_commit": "3f12bebc" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-10-02 14:33:54.609830", - "spec_repo_commit": "3b4747f4" + "regenerated": "2024-10-02 16:22:32.670241", + "spec_repo_commit": "3f12bebc" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 28ad73f8c..b9b317f38 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -18188,7 +18188,6 @@ components: $ref: '#/components/schemas/ToplistWidgetStackedType' required: - type - - legend type: object ToplistWidgetStackedType: default: stacked diff --git a/examples/v1_dashboards_CreateDashboard_1213075383.rs b/examples/v1_dashboards_CreateDashboard_1213075383.rs index b3c7d64ec..9352d1c7a 100644 --- a/examples/v1_dashboards_CreateDashboard_1213075383.rs +++ b/examples/v1_dashboards_CreateDashboard_1213075383.rs @@ -85,9 +85,8 @@ async fn main() { ToplistWidgetDisplay::ToplistWidgetStacked( Box::new( ToplistWidgetStacked::new( - ToplistWidgetLegend::INLINE, ToplistWidgetStackedType::STACKED, - ), + ).legend(ToplistWidgetLegend::INLINE), ), ), ) diff --git a/examples/v1_dashboards_CreateDashboard_1413226400.rs b/examples/v1_dashboards_CreateDashboard_1413226400.rs new file mode 100644 index 000000000..8bfe5e862 --- /dev/null +++ b/examples/v1_dashboards_CreateDashboard_1413226400.rs @@ -0,0 +1,115 @@ +// Create a new dashboard with a toplist widget with stacked type and no legend +// specified +use datadog_api_client::datadog; +use datadog_api_client::datadogV1::api_dashboards::DashboardsAPI; +use datadog_api_client::datadogV1::model::Dashboard; +use datadog_api_client::datadogV1::model::DashboardLayoutType; +use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricAggregation; +use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource; +use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition; +use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition; +use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat; +use datadog_api_client::datadogV1::model::GroupType; +use datadog_api_client::datadogV1::model::ToplistWidgetDefinition; +use datadog_api_client::datadogV1::model::ToplistWidgetDefinitionType; +use datadog_api_client::datadogV1::model::ToplistWidgetDisplay; +use datadog_api_client::datadogV1::model::ToplistWidgetRequest; +use datadog_api_client::datadogV1::model::ToplistWidgetScaling; +use datadog_api_client::datadogV1::model::ToplistWidgetStacked; +use datadog_api_client::datadogV1::model::ToplistWidgetStackedType; +use datadog_api_client::datadogV1::model::ToplistWidgetStyle; +use datadog_api_client::datadogV1::model::Widget; +use datadog_api_client::datadogV1::model::WidgetDefinition; +use datadog_api_client::datadogV1::model::WidgetFormula; +use datadog_api_client::datadogV1::model::WidgetGroupSort; +use datadog_api_client::datadogV1::model::WidgetLayout; +use datadog_api_client::datadogV1::model::WidgetLegacyLiveSpan; +use datadog_api_client::datadogV1::model::WidgetSort; +use datadog_api_client::datadogV1::model::WidgetSortBy; +use datadog_api_client::datadogV1::model::WidgetSortOrderBy; +use datadog_api_client::datadogV1::model::WidgetTextAlign; +use datadog_api_client::datadogV1::model::WidgetTime; + +#[tokio::main] +async fn main() { + let body = + Dashboard::new( + DashboardLayoutType::FREE, + "Example-Dashboard".to_string(), + vec![ + Widget::new( + WidgetDefinition::ToplistWidgetDefinition( + Box::new( + ToplistWidgetDefinition::new( + vec![ + ToplistWidgetRequest::new() + .formulas(vec![WidgetFormula::new("query1".to_string())]) + .queries( + vec![ + FormulaAndFunctionQueryDefinition + ::FormulaAndFunctionMetricQueryDefinition( + Box::new( + FormulaAndFunctionMetricQueryDefinition::new( + FormulaAndFunctionMetricDataSource::METRICS, + "query1".to_string(), + "avg:system.cpu.user{*} by {service}".to_string(), + ).aggregator(FormulaAndFunctionMetricAggregation::AVG), + ), + ) + ], + ) + .response_format(FormulaAndFunctionResponseFormat::SCALAR) + .sort( + WidgetSortBy::new() + .count(10) + .order_by( + vec![ + WidgetSortOrderBy::WidgetGroupSort( + Box::new( + WidgetGroupSort::new( + "service".to_string(), + WidgetSort::ASCENDING, + GroupType::GROUP, + ), + ), + ) + ], + ), + ) + ], + ToplistWidgetDefinitionType::TOPLIST, + ) + .style( + ToplistWidgetStyle::new() + .display( + ToplistWidgetDisplay::ToplistWidgetStacked( + Box::new( + ToplistWidgetStacked::new(ToplistWidgetStackedType::STACKED), + ), + ), + ) + .palette("dog_classic".to_string()) + .scaling(ToplistWidgetScaling::RELATIVE), + ) + .time(WidgetTime::WidgetLegacyLiveSpan(Box::new(WidgetLegacyLiveSpan::new()))) + .title("".to_string()) + .title_align(WidgetTextAlign::LEFT) + .title_size("16".to_string()), + ), + ), + ).layout(WidgetLayout::new(15, 47, 0, 0)) + ], + ) + .description(Some("".to_string())) + .is_read_only(false) + .notify_list(Some(vec![])) + .template_variables(Some(vec![])); + let configuration = datadog::Configuration::new(); + let api = DashboardsAPI::with_config(configuration); + let resp = api.create_dashboard(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v1_dashboards_CreateDashboard_2563642929.rs b/examples/v1_dashboards_CreateDashboard_2563642929.rs index c008057fe..988a0b42e 100644 --- a/examples/v1_dashboards_CreateDashboard_2563642929.rs +++ b/examples/v1_dashboards_CreateDashboard_2563642929.rs @@ -85,9 +85,8 @@ async fn main() { ToplistWidgetDisplay::ToplistWidgetStacked( Box::new( ToplistWidgetStacked::new( - ToplistWidgetLegend::INLINE, ToplistWidgetStackedType::STACKED, - ), + ).legend(ToplistWidgetLegend::INLINE), ), ), ) diff --git a/src/datadogV1/model/model_toplist_widget_stacked.rs b/src/datadogV1/model/model_toplist_widget_stacked.rs index c0e5f7b73..a83ac961e 100644 --- a/src/datadogV1/model/model_toplist_widget_stacked.rs +++ b/src/datadogV1/model/model_toplist_widget_stacked.rs @@ -13,7 +13,7 @@ use std::fmt::{self, Formatter}; pub struct ToplistWidgetStacked { /// Top list widget stacked legend behavior. #[serde(rename = "legend")] - pub legend: crate::datadogV1::model::ToplistWidgetLegend, + pub legend: Option, /// Top list widget stacked display type. #[serde(rename = "type")] pub type_: crate::datadogV1::model::ToplistWidgetStackedType, @@ -25,18 +25,20 @@ pub struct ToplistWidgetStacked { } impl ToplistWidgetStacked { - pub fn new( - legend: crate::datadogV1::model::ToplistWidgetLegend, - type_: crate::datadogV1::model::ToplistWidgetStackedType, - ) -> ToplistWidgetStacked { + pub fn new(type_: crate::datadogV1::model::ToplistWidgetStackedType) -> ToplistWidgetStacked { ToplistWidgetStacked { - legend, + legend: None, type_, additional_properties: std::collections::BTreeMap::new(), _unparsed: false, } } + pub fn legend(mut self, value: crate::datadogV1::model::ToplistWidgetLegend) -> Self { + self.legend = Some(value); + self + } + pub fn additional_properties( mut self, value: std::collections::BTreeMap, @@ -74,6 +76,9 @@ impl<'de> Deserialize<'de> for ToplistWidgetStacked { while let Some((k, v)) = map.next_entry::()? { match k.as_str() { "legend" => { + if v.is_null() { + continue; + } legend = Some(serde_json::from_value(v).map_err(M::Error::custom)?); if let Some(ref _legend) = legend { match _legend { @@ -102,7 +107,6 @@ impl<'de> Deserialize<'de> for ToplistWidgetStacked { } } } - let legend = legend.ok_or_else(|| M::Error::missing_field("legend"))?; let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; let content = ToplistWidgetStacked { diff --git a/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-a-toplist-widget-with-stacked-type-and-no-legend-specified.frozen b/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-a-toplist-widget-with-stacked-type-and-no-legend-specified.frozen new file mode 100644 index 000000000..f6e6007e9 --- /dev/null +++ b/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-a-toplist-widget-with-stacked-type-and-no-legend-specified.frozen @@ -0,0 +1 @@ +2024-09-30T17:24:52.299Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-a-toplist-widget-with-stacked-type-and-no-legend-specified.json b/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-a-toplist-widget-with-stacked-type-and-no-legend-specified.json new file mode 100644 index 000000000..4498d99c2 --- /dev/null +++ b/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-a-toplist-widget-with-stacked-type-and-no-legend-specified.json @@ -0,0 +1,67 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"description\":\"\",\"is_read_only\":false,\"layout_type\":\"free\",\"notify_list\":[],\"template_variables\":[],\"title\":\"Test-Create_a_new_dashboard_with_a_toplist_widget_with_stacked_type_and_no_legend_specified-1727717092\",\"widgets\":[{\"definition\":{\"requests\":[{\"formulas\":[{\"formula\":\"query1\"}],\"queries\":[{\"aggregator\":\"avg\",\"data_source\":\"metrics\",\"name\":\"query1\",\"query\":\"avg:system.cpu.user{*} by {service}\"}],\"response_format\":\"scalar\",\"sort\":{\"count\":10,\"order_by\":[{\"name\":\"service\",\"order\":\"asc\",\"type\":\"group\"}]}}],\"style\":{\"display\":{\"type\":\"stacked\"},\"palette\":\"dog_classic\",\"scaling\":\"relative\"},\"time\":{},\"title\":\"\",\"title_align\":\"left\",\"title_size\":\"16\",\"type\":\"toplist\"},\"layout\":{\"height\":15,\"width\":47,\"x\":0,\"y\":0}}]}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v1/dashboard" + }, + "response": { + "body": { + "string": "{\"id\":\"2az-xeg-xar\",\"title\":\"Test-Create_a_new_dashboard_with_a_toplist_widget_with_stacked_type_and_no_legend_specified-1727717092\",\"description\":\"\",\"author_handle\":\"frog@datadoghq.com\",\"author_name\":null,\"layout_type\":\"free\",\"url\":\"/dashboard/2az-xeg-xar/test-createanewdashboardwithatoplistwidgetwithstackedtypeandnolegendspecified-17\",\"is_read_only\":false,\"template_variables\":[],\"widgets\":[{\"definition\":{\"requests\":[{\"formulas\":[{\"formula\":\"query1\"}],\"queries\":[{\"aggregator\":\"avg\",\"data_source\":\"metrics\",\"name\":\"query1\",\"query\":\"avg:system.cpu.user{*} by {service}\"}],\"response_format\":\"scalar\",\"sort\":{\"count\":10,\"order_by\":[{\"name\":\"service\",\"order\":\"asc\",\"type\":\"group\"}]}}],\"style\":{\"display\":{\"type\":\"stacked\"},\"palette\":\"dog_classic\",\"scaling\":\"relative\"},\"time\":{},\"title\":\"\",\"title_align\":\"left\",\"title_size\":\"16\",\"type\":\"toplist\"},\"layout\":{\"height\":15,\"width\":47,\"x\":0,\"y\":0},\"id\":688132644515996}],\"notify_list\":[],\"created_at\":\"2024-09-30T17:24:52.542207+00:00\",\"modified_at\":\"2024-09-30T17:24:52.542207+00:00\",\"experience_type\":\"default\",\"restricted_roles\":[]}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 30 Sep 2024 17:24:52 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v1/dashboard/2az-xeg-xar" + }, + "response": { + "body": { + "string": "{\"deleted_dashboard_id\":\"2az-xeg-xar\"}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Mon, 30 Sep 2024 17:24:52 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/features/v1/dashboards.feature b/tests/scenarios/features/v1/dashboards.feature index de855fec2..09231d8d7 100644 --- a/tests/scenarios/features/v1/dashboards.feature +++ b/tests/scenarios/features/v1/dashboards.feature @@ -206,6 +206,19 @@ Feature: Dashboards And the response "widgets[0].definition.requests[0].sort.order_by[0].type" is equal to "group" And the response "widgets[0].definition.requests[0].sort.order_by[0].name" is equal to "service" + @skip-typescript @team:DataDog/dashboards-backend + Scenario: Create a new dashboard with a toplist widget with stacked type and no legend specified + Given new "CreateDashboard" request + And body with value {"title":"{{ unique }}","description":"","widgets":[{"layout":{"x":0,"y":0,"width":47,"height":15},"definition":{"title":"","title_size":"16","title_align":"left","time":{},"style":{"display": {"type": "stacked"},"scaling": "relative","palette": "dog_classic"},"type":"toplist","requests":[{"queries":[{"data_source":"metrics","name":"query1","query":"avg:system.cpu.user{*} by {service}","aggregator":"avg"}],"formulas":[{"formula":"query1"}],"sort":{"count":10,"order_by":[{"type":"group","name":"service","order":"asc"}]},"response_format":"scalar"}]}}],"template_variables":[],"layout_type":"free","is_read_only":false,"notify_list":[]} + When the request is sent + Then the response status is 200 OK + And the response "widgets[0].definition.type" is equal to "toplist" + And the response "widgets[0].definition.requests[0].sort.order_by[0].order" is equal to "asc" + And the response "widgets[0].definition.requests[0].sort.order_by[0].type" is equal to "group" + And the response "widgets[0].definition.requests[0].sort.order_by[0].name" is equal to "service" + And the response "widgets[0].definition.style.display.type" is equal to "stacked" + And the response "widgets[0].definition.style.display" does not have field "legend" + @team:DataDog/dashboards-backend Scenario: Create a new dashboard with alert_graph widget Given there is a valid "monitor" in the system