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
65 changes: 65 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,10 @@ components:
format: date-time
readOnly: true
type: string
default_timeframe:
$ref: "#/components/schemas/DashboardDefaultTimeframeSetting"
description: The default timeframe applied when opening the dashboard. Set to `null` to clear.
nullable: true
description:
description: Description of the dashboard.
nullable: true
Expand Down Expand Up @@ -1557,13 +1561,48 @@ components:
required:
- data
type: object
DashboardDefaultTimeframeSetting:
description: The default timeframe applied when opening the dashboard. Set to `null` to clear the dashboard's default timeframe.
oneOf:
- $ref: "#/components/schemas/DashboardLiveTimeframe"
- $ref: "#/components/schemas/DashboardFixedTimeframe"
DashboardDeleteResponse:
description: Response from the delete dashboard call.
properties:
deleted_dashboard_id:
description: ID of the deleted dashboard.
type: string
type: object
DashboardFixedTimeframe:
description: A fixed dashboard timeframe.
properties:
from:
description: Start time in milliseconds since epoch.
example: 1712080128000
format: int64
minimum: 0
type: integer
to:
description: End time in milliseconds since epoch.
example: 1712083128000
format: int64
minimum: 0
type: integer
type:
$ref: "#/components/schemas/DashboardFixedTimeframeType"
required:
- type
- from
- to
type: object
DashboardFixedTimeframeType:
description: Type of fixed timeframe.
enum:
- fixed
example: fixed
type: string
x-enum-varnames:
- FIXED
DashboardGlobalTime:
description: Object containing the live span selection for the dashboard.
properties:
Expand Down Expand Up @@ -1672,6 +1711,32 @@ components:
$ref: "#/components/schemas/DashboardList"
type: array
type: object
DashboardLiveTimeframe:
description: A live dashboard timeframe.
properties:
type:
$ref: "#/components/schemas/DashboardLiveTimeframeType"
unit:
$ref: "#/components/schemas/WidgetLiveSpanUnit"
value:
description: Value of the live timeframe span.
example: 4
format: int64
minimum: 1
type: integer
required:
- type
- value
- unit
type: object
DashboardLiveTimeframeType:
description: Type of live timeframe.
enum:
- live
example: live
type: string
x-enum-varnames:
- LIVE
DashboardReflowType:
description: |-
Reflow type for a **new dashboard layout** dashboard. Set this only when layout type is 'ordered'.
Expand Down
49 changes: 49 additions & 0 deletions examples/v1_dashboards_CreateDashboard_4032568083.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Create a new dashboard with a live default_timeframe returns "OK" response
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::DashboardDefaultTimeframeSetting;
use datadog_api_client::datadogV1::model::DashboardLayoutType;
use datadog_api_client::datadogV1::model::DashboardLiveTimeframe;
use datadog_api_client::datadogV1::model::DashboardLiveTimeframeType;
use datadog_api_client::datadogV1::model::NoteWidgetDefinition;
use datadog_api_client::datadogV1::model::NoteWidgetDefinitionType;
use datadog_api_client::datadogV1::model::Widget;
use datadog_api_client::datadogV1::model::WidgetDefinition;
use datadog_api_client::datadogV1::model::WidgetLiveSpanUnit;
use datadog_api_client::datadogV1::model::WidgetTextAlign;
use datadog_api_client::datadogV1::model::WidgetTickEdge;

#[tokio::main]
async fn main() {
let body = Dashboard::new(
DashboardLayoutType::ORDERED,
"Example-Dashboard".to_string(),
vec![Widget::new(WidgetDefinition::NoteWidgetDefinition(
Box::new(
NoteWidgetDefinition::new("test".to_string(), NoteWidgetDefinitionType::NOTE)
.background_color("white".to_string())
.font_size("14".to_string())
.show_tick(false)
.text_align(WidgetTextAlign::LEFT)
.tick_edge(WidgetTickEdge::LEFT)
.tick_pos("50%".to_string()),
),
))],
)
.default_timeframe(DashboardDefaultTimeframeSetting::DashboardLiveTimeframe(
Box::new(DashboardLiveTimeframe::new(
DashboardLiveTimeframeType::LIVE,
WidgetLiveSpanUnit::HOUR,
4,
)),
));
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());
}
}
14 changes: 12 additions & 2 deletions src/datadogV1/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ pub mod model_dashboard_restore_request;
pub use self::model_dashboard_restore_request::DashboardRestoreRequest;
pub mod model_dashboard;
pub use self::model_dashboard::Dashboard;
pub mod model_dashboard_live_timeframe;
pub use self::model_dashboard_live_timeframe::DashboardLiveTimeframe;
pub mod model_dashboard_live_timeframe_type;
pub use self::model_dashboard_live_timeframe_type::DashboardLiveTimeframeType;
pub mod model_widget_live_span_unit;
pub use self::model_widget_live_span_unit::WidgetLiveSpanUnit;
pub mod model_dashboard_fixed_timeframe;
pub use self::model_dashboard_fixed_timeframe::DashboardFixedTimeframe;
pub mod model_dashboard_fixed_timeframe_type;
pub use self::model_dashboard_fixed_timeframe_type::DashboardFixedTimeframeType;
pub mod model_dashboard_default_timeframe_setting;
pub use self::model_dashboard_default_timeframe_setting::DashboardDefaultTimeframeSetting;
pub mod model_dashboard_reflow_type;
pub use self::model_dashboard_reflow_type::DashboardReflowType;
pub mod model_dashboard_tab;
Expand All @@ -110,8 +122,6 @@ pub mod model_widget_new_live_span;
pub use self::model_widget_new_live_span::WidgetNewLiveSpan;
pub mod model_widget_new_live_span_type;
pub use self::model_widget_new_live_span_type::WidgetNewLiveSpanType;
pub mod model_widget_live_span_unit;
pub use self::model_widget_live_span_unit::WidgetLiveSpanUnit;
pub mod model_widget_new_fixed_span;
pub use self::model_widget_new_fixed_span::WidgetNewFixedSpan;
pub mod model_widget_new_fixed_span_type;
Expand Down
32 changes: 32 additions & 0 deletions src/datadogV1/model/model_dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub struct Dashboard {
/// Creation date of the dashboard.
#[serde(rename = "created_at")]
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
/// The default timeframe applied when opening the dashboard. Set to `null` to clear the dashboard's default timeframe.
#[serde(rename = "default_timeframe")]
pub default_timeframe: Option<crate::datadogV1::model::DashboardDefaultTimeframeSetting>,
/// Description of the dashboard.
#[serde(
rename = "description",
Expand Down Expand Up @@ -110,6 +113,7 @@ impl Dashboard {
author_handle: None,
author_name: None,
created_at: None,
default_timeframe: None,
description: None,
id: None,
is_read_only: None,
Expand Down Expand Up @@ -148,6 +152,15 @@ impl Dashboard {
self
}

#[allow(deprecated)]
pub fn default_timeframe(
mut self,
value: crate::datadogV1::model::DashboardDefaultTimeframeSetting,
) -> Self {
self.default_timeframe = Some(value);
self
}

#[allow(deprecated)]
pub fn description(mut self, value: Option<String>) -> Self {
self.description = Some(value);
Expand Down Expand Up @@ -255,6 +268,9 @@ impl<'de> Deserialize<'de> for Dashboard {
let mut author_handle: Option<String> = None;
let mut author_name: Option<Option<String>> = None;
let mut created_at: Option<chrono::DateTime<chrono::Utc>> = None;
let mut default_timeframe: Option<
crate::datadogV1::model::DashboardDefaultTimeframeSetting,
> = None;
let mut description: Option<Option<String>> = None;
let mut id: Option<String> = None;
let mut is_read_only: Option<bool> = None;
Expand Down Expand Up @@ -299,6 +315,21 @@ impl<'de> Deserialize<'de> for Dashboard {
}
created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"default_timeframe" => {
if v.is_null() {
continue;
}
default_timeframe =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _default_timeframe) = default_timeframe {
match _default_timeframe {
crate::datadogV1::model::DashboardDefaultTimeframeSetting::UnparsedObject(_default_timeframe) => {
_unparsed = true;
},
_ => {}
}
}
}
"description" => {
description =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
Expand Down Expand Up @@ -404,6 +435,7 @@ impl<'de> Deserialize<'de> for Dashboard {
author_handle,
author_name,
created_at,
default_timeframe,
description,
id,
is_read_only,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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};

/// The default timeframe applied when opening the dashboard. Set to `null` to clear the dashboard's default timeframe.
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(untagged)]
pub enum DashboardDefaultTimeframeSetting {
DashboardLiveTimeframe(Box<crate::datadogV1::model::DashboardLiveTimeframe>),
DashboardFixedTimeframe(Box<crate::datadogV1::model::DashboardFixedTimeframe>),
UnparsedObject(crate::datadog::UnparsedObject),
}

impl<'de> Deserialize<'de> for DashboardDefaultTimeframeSetting {
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::<Box<crate::datadogV1::model::DashboardLiveTimeframe>>(
value.clone(),
) {
if !_v._unparsed {
return Ok(DashboardDefaultTimeframeSetting::DashboardLiveTimeframe(_v));
}
}
if let Ok(_v) = serde_json::from_value::<
Box<crate::datadogV1::model::DashboardFixedTimeframe>,
>(value.clone())
{
if !_v._unparsed {
return Ok(DashboardDefaultTimeframeSetting::DashboardFixedTimeframe(
_v,
));
}
}

return Ok(DashboardDefaultTimeframeSetting::UnparsedObject(
crate::datadog::UnparsedObject { value },
));
}
}
Loading
Loading