diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 7056d83d6..817b35746 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -1780,14 +1780,11 @@ components: - INVITE - EMBED DashboardSummary: - description: Dashboard summary response. - properties: - dashboards: - description: List of dashboard definitions. - items: - $ref: "#/components/schemas/DashboardSummaryDefinition" - type: array - type: object + description: Dashboard summary response with API-versioned representations. + oneOf: + - $ref: "#/components/schemas/DashboardSummary_V1" + - $ref: "#/components/schemas/DashboardSummary_20270101" + x-datadog-api-versioned: true DashboardSummaryDefinition: description: Dashboard definition. properties: @@ -1825,6 +1822,108 @@ components: description: URL of the dashboard. type: string type: object + DashboardSummaryDefinition_20270101: + description: Dashboard definition. + properties: + author: + $ref: "#/components/schemas/Creator" + created: + description: Date of creation of the dashboard. + format: date-time + nullable: true + readOnly: true + type: string + icon: + description: URL to the icon of the dashboard. + nullable: true + readOnly: true + type: string + id: + $ref: "#/components/schemas/DashboardSummaryID_20270101" + integration_id: + description: The short name of the integration. + nullable: true + readOnly: true + type: string + is_favorite: + description: Whether the dashboard is in the favorites. + readOnly: true + type: boolean + is_read_only: + description: Whether the dashboard is read only. + readOnly: true + type: boolean + is_shared: + description: Whether the dashboard is publicly shared. + readOnly: true + type: boolean + last_view_date: + description: Date when the dashboard was last viewed. + nullable: true + readOnly: true + type: string + modified: + description: Date of last edition of the dashboard. + format: date-time + nullable: true + readOnly: true + type: string + popularity: + description: Popularity of the dashboard. + format: int32 + maximum: 5 + readOnly: true + type: integer + tags: + description: List of team names representing ownership of the dashboard. + items: + description: The name of a Datadog team, formatted as `team:`. + type: string + nullable: true + readOnly: true + type: array + title: + description: Title of the dashboard. + readOnly: true + type: string + type: + description: The type of the dashboard. + readOnly: true + type: string + url: + description: URL path to the dashboard. + readOnly: true + type: string + type: object + DashboardSummaryID_20270101: + description: ID of the dashboard. + oneOf: + - type: string + - format: int64 + type: integer + DashboardSummary_20270101: + description: Dashboard summary response. + properties: + dashboards: + description: List of dashboard definitions. + items: + $ref: "#/components/schemas/DashboardSummaryDefinition_20270101" + type: array + total: + description: Number of dashboards. + format: int64 + readOnly: true + type: integer + type: object + DashboardSummary_V1: + description: Dashboard summary response. + properties: + dashboards: + description: List of dashboard definitions. + items: + $ref: "#/components/schemas/DashboardSummaryDefinition" + type: array + type: object DashboardTab: description: Dashboard tab for organizing widgets. properties: diff --git a/src/datadogV1/model/mod.rs b/src/datadogV1/model/mod.rs index 9739508fe..7f5d605cc 100644 --- a/src/datadogV1/model/mod.rs +++ b/src/datadogV1/model/mod.rs @@ -78,12 +78,12 @@ pub mod model_dashboard_bulk_action_data; pub use self::model_dashboard_bulk_action_data::DashboardBulkActionData; pub mod model_dashboard_resource_type; pub use self::model_dashboard_resource_type::DashboardResourceType; -pub mod model_dashboard_summary; -pub use self::model_dashboard_summary::DashboardSummary; pub mod model_dashboard_summary_definition; pub use self::model_dashboard_summary_definition::DashboardSummaryDefinition; pub mod model_dashboard_layout_type; pub use self::model_dashboard_layout_type::DashboardLayoutType; +pub mod model_creator; +pub use self::model_creator::Creator; pub mod model_dashboard_restore_request; pub use self::model_dashboard_restore_request::DashboardRestoreRequest; pub mod model_dashboard; @@ -944,8 +944,6 @@ pub mod model_dashboard_list_list_response; pub use self::model_dashboard_list_list_response::DashboardListListResponse; pub mod model_dashboard_list; pub use self::model_dashboard_list::DashboardList; -pub mod model_creator; -pub use self::model_creator::Creator; pub mod model_dashboard_list_delete_response; pub use self::model_dashboard_list_delete_response::DashboardListDeleteResponse; pub mod model_shared_dashboard; @@ -2328,3 +2326,5 @@ pub mod model_http_log_item; pub use self::model_http_log_item::HTTPLogItem; pub mod model_http_log_error; pub use self::model_http_log_error::HTTPLogError; +pub mod model_dashboard_summary; +pub use self::model_dashboard_summary::DashboardSummary; diff --git a/src/datadogV1_20270101/api/api_dashboards.rs b/src/datadogV1_20270101/api/api_dashboards.rs new file mode 100644 index 000000000..abbee5571 --- /dev/null +++ b/src/datadogV1_20270101/api/api_dashboards.rs @@ -0,0 +1,307 @@ +// 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 crate::datadog; +use async_stream::try_stream; +use futures_core::stream::Stream; +use reqwest::header::{HeaderMap, HeaderValue}; +use serde::{Deserialize, Serialize}; + +/// ListDashboardsOptionalParams is a struct for passing parameters to the method [`DashboardsAPI::list_dashboards`] +#[non_exhaustive] +#[derive(Clone, Default, Debug)] +pub struct ListDashboardsOptionalParams { + /// When `true`, this query only returns shared custom created + /// or cloned dashboards. + pub filter_shared: Option, + /// When `true`, this query returns only deleted custom-created + /// or cloned dashboards. This parameter is incompatible with `filter[shared]`. + pub filter_deleted: Option, + /// The maximum number of dashboards returned in the list. + pub count: Option, + /// The specific offset to use as the beginning of the returned response. + pub start: Option, +} + +impl ListDashboardsOptionalParams { + /// When `true`, this query only returns shared custom created + /// or cloned dashboards. + pub fn filter_shared(mut self, value: bool) -> Self { + self.filter_shared = Some(value); + self + } + /// When `true`, this query returns only deleted custom-created + /// or cloned dashboards. This parameter is incompatible with `filter[shared]`. + pub fn filter_deleted(mut self, value: bool) -> Self { + self.filter_deleted = Some(value); + self + } + /// The maximum number of dashboards returned in the list. + pub fn count(mut self, value: i64) -> Self { + self.count = Some(value); + self + } + /// The specific offset to use as the beginning of the returned response. + pub fn start(mut self, value: i64) -> Self { + self.start = Some(value); + self + } +} + +/// ListDashboardsError is a struct for typed errors of method [`DashboardsAPI::list_dashboards`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListDashboardsError { + APIErrorResponse(crate::datadogV1::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// Manage all your dashboards, as well as access to your shared dashboards, through the API. See the [Dashboards page]() for more information. +#[derive(Debug, Clone)] +pub struct DashboardsAPI { + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, +} + +impl Default for DashboardsAPI { + fn default() -> Self { + Self::with_config(datadog::Configuration::default()) + } +} + +impl DashboardsAPI { + pub fn new() -> Self { + Self::default() + } + pub fn with_config(config: datadog::Configuration) -> Self { + let reqwest_client_builder = { + let builder = config.apply_headers(reqwest::Client::builder()); + #[cfg(not(target_arch = "wasm32"))] + let builder = if let Some(proxy_url) = &config.proxy_url { + builder.proxy(reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL")) + } else { + builder + }; + builder + }; + + let middleware_client_builder = { + let builder = + reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap()); + #[cfg(feature = "retry")] + let builder = if config.enable_retry { + struct RetryableStatus; + impl reqwest_retry::RetryableStrategy for RetryableStatus { + fn handle( + &self, + res: &Result, + ) -> Option { + match res { + Ok(success) => reqwest_retry::default_on_request_success(success), + Err(_) => None, + } + } + } + let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder() + .build_with_max_retries(config.max_retries); + + let retry_middleware = + reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy( + backoff_policy, + RetryableStatus, + ); + + builder.with(retry_middleware) + } else { + builder + }; + builder + }; + + let client = middleware_client_builder.build(); + + Self { config, client } + } + + pub fn with_client_and_config( + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, + ) -> Self { + Self { config, client } + } + + /// Get all dashboards. + /// + /// **Note**: This query will only return custom created or cloned dashboards. + /// This query will not return preset dashboards. + pub async fn list_dashboards( + &self, + params: ListDashboardsOptionalParams, + ) -> Result< + crate::datadogV1_20270101::model::DashboardSummary, + datadog::Error, + > { + match self.list_dashboards_with_http_info(params).await { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + pub fn list_dashboards_with_pagination( + &self, + mut params: ListDashboardsOptionalParams, + ) -> impl Stream< + Item = Result< + crate::datadogV1_20270101::model::DashboardSummaryDefinition, + datadog::Error, + >, + > + '_ { + try_stream! { + let mut page_size: i64 = 100; + if params.count.is_none() { + params.count = Some(page_size); + } else { + page_size = params.count.unwrap().clone(); + } + loop { + let resp = self.list_dashboards(params.clone()).await?; + let Some(dashboards) = resp.dashboards else { break }; + + let r = dashboards; + let count = r.len(); + for team in r { + yield team; + } + if count < page_size as usize { + break; + } + if params.start.is_none() { + params.start = Some(page_size.clone()); + } else { + params.start = Some(params.start.unwrap() + page_size.clone()); + } + } + } + } + + /// Get all dashboards. + /// + /// **Note**: This query will only return custom created or cloned dashboards. + /// This query will not return preset dashboards. + pub async fn list_dashboards_with_http_info( + &self, + params: ListDashboardsOptionalParams, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let local_operation_id = "v1_20270101.list_dashboards"; + + // unbox and build optional parameters + let filter_shared = params.filter_shared; + let filter_deleted = params.filter_deleted; + let count = params.count; + let start = params.start; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v1/dashboard", + local_configuration.get_operation_host(local_operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + if let Some(ref local_query_param) = filter_shared { + local_req_builder = + local_req_builder.query(&[("filter[shared]", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = filter_deleted { + local_req_builder = + local_req_builder.query(&[("filter[deleted]", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = count { + local_req_builder = + local_req_builder.query(&[("count", &local_query_param.to_string())]); + }; + if let Some(ref local_query_param) = start { + local_req_builder = + local_req_builder.query(&[("start", &local_query_param.to_string())]); + }; + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Accept", HeaderValue::from_static("application/json")); + headers.insert("DD-API-Version", HeaderValue::from_static("2027-01-01")); + + // build user agent + match HeaderValue::from_str(local_configuration.user_agent.as_str()) { + Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent), + Err(e) => { + log::warn!("Failed to parse user agent header: {e}, falling back to default"); + headers.insert( + reqwest::header::USER_AGENT, + HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()), + ) + } + }; + + // build auth + if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") { + headers.insert( + "DD-API-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-API-KEY header"), + ); + }; + if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") { + headers.insert( + "DD-APPLICATION-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-APPLICATION-KEY header"), + ); + }; + + local_req_builder = local_req_builder.headers(headers); + let local_req = local_req_builder.build()?; + log::debug!("request content: {:?}", local_req.body()); + let local_resp = local_client.execute(local_req).await?; + + let local_status = local_resp.status(); + let local_content = local_resp.text().await?; + log::debug!("response content: {}", local_content); + + if !local_status.is_client_error() && !local_status.is_server_error() { + match serde_json::from_str::( + &local_content, + ) { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + serde_json::from_str(&local_content).ok(); + let local_error = datadog::ResponseContent { + status: local_status, + content: local_content, + entity: local_entity, + }; + Err(datadog::Error::ResponseError(local_error)) + } + } +} diff --git a/src/datadogV1_20270101/api/mod.rs b/src/datadogV1_20270101/api/mod.rs new file mode 100644 index 000000000..2c1128641 --- /dev/null +++ b/src/datadogV1_20270101/api/mod.rs @@ -0,0 +1,5 @@ +// 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. + +pub mod api_dashboards; diff --git a/src/datadogV1_20270101/mod.rs b/src/datadogV1_20270101/mod.rs new file mode 100644 index 000000000..b8c41fbbc --- /dev/null +++ b/src/datadogV1_20270101/mod.rs @@ -0,0 +1,7 @@ +// 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. + +pub mod api; +pub use self::api::api_dashboards; +pub mod model; diff --git a/src/datadogV1_20270101/model/mod.rs b/src/datadogV1_20270101/model/mod.rs new file mode 100644 index 000000000..820d0c34f --- /dev/null +++ b/src/datadogV1_20270101/model/mod.rs @@ -0,0 +1,10 @@ +// 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. + +pub mod model_dashboard_summary; +pub use self::model_dashboard_summary::DashboardSummary; +pub mod model_dashboard_summary_definition; +pub use self::model_dashboard_summary_definition::DashboardSummaryDefinition; +pub mod model_dashboard_summary_id; +pub use self::model_dashboard_summary_id::DashboardSummaryID; diff --git a/src/datadogV1_20270101/model/model_dashboard_summary.rs b/src/datadogV1_20270101/model/model_dashboard_summary.rs new file mode 100644 index 000000000..029399553 --- /dev/null +++ b/src/datadogV1_20270101/model/model_dashboard_summary.rs @@ -0,0 +1,127 @@ +// 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::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Dashboard summary response. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DashboardSummary { + /// List of dashboard definitions. + #[serde(rename = "dashboards")] + pub dashboards: Option>, + /// Number of dashboards. + #[serde(rename = "total")] + pub total: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DashboardSummary { + pub fn new() -> DashboardSummary { + DashboardSummary { + dashboards: None, + total: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn dashboards( + mut self, + value: Vec, + ) -> Self { + self.dashboards = Some(value); + self + } + + pub fn total(mut self, value: i64) -> Self { + self.total = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for DashboardSummary { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for DashboardSummary { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DashboardSummaryVisitor; + impl<'a> Visitor<'a> for DashboardSummaryVisitor { + type Value = DashboardSummary; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut dashboards: Option< + Vec, + > = None; + let mut total: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "dashboards" => { + if v.is_null() { + continue; + } + dashboards = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "total" => { + if v.is_null() { + continue; + } + total = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = DashboardSummary { + dashboards, + total, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DashboardSummaryVisitor) + } +} diff --git a/src/datadogV1_20270101/model/model_dashboard_summary_definition.rs b/src/datadogV1_20270101/model/model_dashboard_summary_definition.rs new file mode 100644 index 000000000..a0dedaaf9 --- /dev/null +++ b/src/datadogV1_20270101/model/model_dashboard_summary_definition.rs @@ -0,0 +1,353 @@ +// 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::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Dashboard definition. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DashboardSummaryDefinition { + /// Object describing the creator of the shared element. + #[serde(rename = "author")] + pub author: Option, + /// Date of creation of the dashboard. + #[serde( + rename = "created", + default, + with = "::serde_with::rust::double_option" + )] + pub created: Option>>, + /// URL to the icon of the dashboard. + #[serde(rename = "icon", default, with = "::serde_with::rust::double_option")] + pub icon: Option>, + /// ID of the dashboard. + #[serde(rename = "id")] + pub id: Option, + /// The short name of the integration. + #[serde( + rename = "integration_id", + default, + with = "::serde_with::rust::double_option" + )] + pub integration_id: Option>, + /// Whether the dashboard is in the favorites. + #[serde(rename = "is_favorite")] + pub is_favorite: Option, + /// Whether the dashboard is read only. + #[serde(rename = "is_read_only")] + pub is_read_only: Option, + /// Whether the dashboard is publicly shared. + #[serde(rename = "is_shared")] + pub is_shared: Option, + /// Date when the dashboard was last viewed. + #[serde( + rename = "last_view_date", + default, + with = "::serde_with::rust::double_option" + )] + pub last_view_date: Option>, + /// Date of last edition of the dashboard. + #[serde( + rename = "modified", + default, + with = "::serde_with::rust::double_option" + )] + pub modified: Option>>, + /// Popularity of the dashboard. + #[serde(rename = "popularity")] + pub popularity: Option, + /// List of team names representing ownership of the dashboard. + #[serde(rename = "tags", default, with = "::serde_with::rust::double_option")] + pub tags: Option>>, + /// Title of the dashboard. + #[serde(rename = "title")] + pub title: Option, + /// The type of the dashboard. + #[serde(rename = "type")] + pub type_: Option, + /// URL path to the dashboard. + #[serde(rename = "url")] + pub url: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DashboardSummaryDefinition { + pub fn new() -> DashboardSummaryDefinition { + DashboardSummaryDefinition { + author: None, + created: None, + icon: None, + id: None, + integration_id: None, + is_favorite: None, + is_read_only: None, + is_shared: None, + last_view_date: None, + modified: None, + popularity: None, + tags: None, + title: None, + type_: None, + url: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn author(mut self, value: crate::datadogV1::model::Creator) -> Self { + self.author = Some(value); + self + } + + pub fn created(mut self, value: Option>) -> Self { + self.created = Some(value); + self + } + + pub fn icon(mut self, value: Option) -> Self { + self.icon = Some(value); + self + } + + pub fn id(mut self, value: crate::datadogV1_20270101::model::DashboardSummaryID) -> Self { + self.id = Some(value); + self + } + + pub fn integration_id(mut self, value: Option) -> Self { + self.integration_id = Some(value); + self + } + + pub fn is_favorite(mut self, value: bool) -> Self { + self.is_favorite = Some(value); + self + } + + pub fn is_read_only(mut self, value: bool) -> Self { + self.is_read_only = Some(value); + self + } + + pub fn is_shared(mut self, value: bool) -> Self { + self.is_shared = Some(value); + self + } + + pub fn last_view_date(mut self, value: Option) -> Self { + self.last_view_date = Some(value); + self + } + + pub fn modified(mut self, value: Option>) -> Self { + self.modified = Some(value); + self + } + + pub fn popularity(mut self, value: i32) -> Self { + self.popularity = Some(value); + self + } + + pub fn tags(mut self, value: Option>) -> Self { + self.tags = Some(value); + self + } + + pub fn title(mut self, value: String) -> Self { + self.title = Some(value); + self + } + + pub fn type_(mut self, value: String) -> Self { + self.type_ = Some(value); + self + } + + pub fn url(mut self, value: String) -> Self { + self.url = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for DashboardSummaryDefinition { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for DashboardSummaryDefinition { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DashboardSummaryDefinitionVisitor; + impl<'a> Visitor<'a> for DashboardSummaryDefinitionVisitor { + type Value = DashboardSummaryDefinition; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut author: Option = None; + let mut created: Option>> = None; + let mut icon: Option> = None; + let mut id: Option = None; + let mut integration_id: Option> = None; + let mut is_favorite: Option = None; + let mut is_read_only: Option = None; + let mut is_shared: Option = None; + let mut last_view_date: Option> = None; + let mut modified: Option>> = None; + let mut popularity: Option = None; + let mut tags: Option>> = None; + let mut title: Option = None; + let mut type_: Option = None; + let mut url: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "author" => { + if v.is_null() { + continue; + } + author = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "created" => { + created = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "icon" => { + icon = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + if v.is_null() { + continue; + } + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _id) = id { + match _id { + crate::datadogV1_20270101::model::DashboardSummaryID::UnparsedObject(_id) => { + _unparsed = true; + }, + _ => {} + } + } + } + "integration_id" => { + integration_id = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "is_favorite" => { + if v.is_null() { + continue; + } + is_favorite = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "is_read_only" => { + if v.is_null() { + continue; + } + is_read_only = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "is_shared" => { + if v.is_null() { + continue; + } + is_shared = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "last_view_date" => { + last_view_date = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "modified" => { + modified = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "popularity" => { + if v.is_null() { + continue; + } + popularity = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "tags" => { + tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "title" => { + if v.is_null() { + continue; + } + title = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + if v.is_null() { + continue; + } + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "url" => { + if v.is_null() { + continue; + } + url = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = DashboardSummaryDefinition { + author, + created, + icon, + id, + integration_id, + is_favorite, + is_read_only, + is_shared, + last_view_date, + modified, + popularity, + tags, + title, + type_, + url, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DashboardSummaryDefinitionVisitor) + } +} diff --git a/src/datadogV1_20270101/model/model_dashboard_summary_id.rs b/src/datadogV1_20270101/model/model_dashboard_summary_id.rs new file mode 100644 index 000000000..1e4368dd5 --- /dev/null +++ b/src/datadogV1_20270101/model/model_dashboard_summary_id.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}; + +/// ID of the dashboard. +#[non_exhaustive] +#[derive(Clone, Debug, PartialEq, Serialize)] +#[serde(untagged)] +pub enum DashboardSummaryID { + String(String), + I64(i64), + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl<'de> Deserialize<'de> for DashboardSummaryID { + 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(DashboardSummaryID::String(_v)); + } + if let Ok(_v) = serde_json::from_value::(value.clone()) { + return Ok(DashboardSummaryID::I64(_v)); + } + + return Ok(DashboardSummaryID::UnparsedObject( + crate::datadog::UnparsedObject { value }, + )); + } +} diff --git a/src/lib.rs b/src/lib.rs index 7ceb7d5aa..76f6e0a18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,4 +7,5 @@ pub mod datadog; pub mod datadogV1; +pub mod datadogV1_20270101; pub mod datadogV2; diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index b02ffb24f..dd616db96 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -7,6 +7,7 @@ use std::collections::HashMap; use datadog_api_client::datadog::*; use datadog_api_client::datadogV1; +use datadog_api_client::datadogV1_20270101; use datadog_api_client::datadogV2; #[derive(Debug, Default)] @@ -49,6 +50,7 @@ pub struct ApiInstances { pub v1_api_tags: Option, pub v1_api_users: Option, pub v1_api_authentication: Option, + pub v1_20270101_api_dashboards: Option, pub v2_api_fleet_automation: Option, pub v2_api_agent_observability: Option, @@ -298,6 +300,12 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) { world.http_client.as_ref().unwrap().clone(), ), ); + world.api_instances.v1_20270101_api_dashboards = Some( + datadogV1_20270101::api_dashboards::DashboardsAPI::with_client_and_config( + world.config.clone(), + world.http_client.as_ref().unwrap().clone(), + ), + ); world.api_instances.v2_api_dashboards = Some( datadogV2::api_dashboards::DashboardsAPI::with_client_and_config( world.config.clone(), @@ -2365,6 +2373,14 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { world .function_mappings .insert("v1.Validate".into(), test_v1_validate); + world.function_mappings.insert( + "v1_20270101.ListDashboards".into(), + test_v1_20270101_list_dashboards, + ); + world.function_mappings.insert( + "v1_20270101.ListDashboardsWithPagination".into(), + test_v1_20270101_list_dashboards_with_pagination, + ); world.function_mappings.insert( "v2.ListFleetAgentTracers".into(), test_v2_list_fleet_agent_tracers, @@ -15575,6 +15591,103 @@ fn test_v1_validate(world: &mut DatadogWorld, _parameters: &HashMap, +) { + let api = world + .api_instances + .v1_20270101_api_dashboards + .as_ref() + .expect("api instance not found"); + let filter_shared = _parameters + .get("filter[shared]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let filter_deleted = _parameters + .get("filter[deleted]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let count = _parameters + .get("count") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let start = _parameters + .get("start") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = datadogV1_20270101::api_dashboards::ListDashboardsOptionalParams::default(); + params.filter_shared = filter_shared; + params.filter_deleted = filter_deleted; + params.count = count; + params.start = start; + let response = match block_on(api.list_dashboards_with_http_info(params)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} +fn test_v1_20270101_list_dashboards_with_pagination( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v1_20270101_api_dashboards + .as_ref() + .expect("api instance not found"); + let filter_shared = _parameters + .get("filter[shared]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let filter_deleted = _parameters + .get("filter[deleted]") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let count = _parameters + .get("count") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let start = _parameters + .get("start") + .and_then(|param| Some(serde_json::from_value(param.clone()).unwrap())); + let mut params = datadogV1_20270101::api_dashboards::ListDashboardsOptionalParams::default(); + params.filter_shared = filter_shared; + params.filter_deleted = filter_deleted; + params.count = count; + params.start = start; + let response = api.list_dashboards_with_pagination(params); + let mut result = Vec::new(); + + block_on(async { + pin_mut!(response); + + while let Some(resp) = response.next().await { + match resp { + Ok(response) => { + result.push(response); + } + Err(error) => { + return match error { + Error::ResponseError(e) => { + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {}", error), + }; + } + } + } + }); + world.response.object = serde_json::to_value(result).unwrap(); + world.response.code = 200; +} + fn test_v2_list_fleet_agent_tracers( world: &mut DatadogWorld, _parameters: &HashMap,