datadog_api_client/datadogV1/model/
model_tree_map_widget_request.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// An updated treemap widget.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct TreeMapWidgetRequest {
14    /// List of formulas that operate on queries.
15    #[serde(rename = "formulas")]
16    pub formulas: Option<Vec<crate::datadogV1::model::WidgetFormula>>,
17    /// The widget metrics query.
18    #[serde(rename = "q")]
19    pub q: Option<String>,
20    /// List of queries that can be returned directly or used in formulas.
21    #[serde(rename = "queries")]
22    pub queries: Option<Vec<crate::datadogV1::model::FormulaAndFunctionQueryDefinition>>,
23    /// Timeseries, scalar, or event list response. Event list response formats are supported by Geomap widgets.
24    #[serde(rename = "response_format")]
25    pub response_format: Option<crate::datadogV1::model::FormulaAndFunctionResponseFormat>,
26    #[serde(flatten)]
27    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
28    #[serde(skip)]
29    #[serde(default)]
30    pub(crate) _unparsed: bool,
31}
32
33impl TreeMapWidgetRequest {
34    pub fn new() -> TreeMapWidgetRequest {
35        TreeMapWidgetRequest {
36            formulas: None,
37            q: None,
38            queries: None,
39            response_format: None,
40            additional_properties: std::collections::BTreeMap::new(),
41            _unparsed: false,
42        }
43    }
44
45    pub fn formulas(mut self, value: Vec<crate::datadogV1::model::WidgetFormula>) -> Self {
46        self.formulas = Some(value);
47        self
48    }
49
50    pub fn q(mut self, value: String) -> Self {
51        self.q = Some(value);
52        self
53    }
54
55    pub fn queries(
56        mut self,
57        value: Vec<crate::datadogV1::model::FormulaAndFunctionQueryDefinition>,
58    ) -> Self {
59        self.queries = Some(value);
60        self
61    }
62
63    pub fn response_format(
64        mut self,
65        value: crate::datadogV1::model::FormulaAndFunctionResponseFormat,
66    ) -> Self {
67        self.response_format = Some(value);
68        self
69    }
70
71    pub fn additional_properties(
72        mut self,
73        value: std::collections::BTreeMap<String, serde_json::Value>,
74    ) -> Self {
75        self.additional_properties = value;
76        self
77    }
78}
79
80impl Default for TreeMapWidgetRequest {
81    fn default() -> Self {
82        Self::new()
83    }
84}
85
86impl<'de> Deserialize<'de> for TreeMapWidgetRequest {
87    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
88    where
89        D: Deserializer<'de>,
90    {
91        struct TreeMapWidgetRequestVisitor;
92        impl<'a> Visitor<'a> for TreeMapWidgetRequestVisitor {
93            type Value = TreeMapWidgetRequest;
94
95            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
96                f.write_str("a mapping")
97            }
98
99            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
100            where
101                M: MapAccess<'a>,
102            {
103                let mut formulas: Option<Vec<crate::datadogV1::model::WidgetFormula>> = None;
104                let mut q: Option<String> = None;
105                let mut queries: Option<
106                    Vec<crate::datadogV1::model::FormulaAndFunctionQueryDefinition>,
107                > = None;
108                let mut response_format: Option<
109                    crate::datadogV1::model::FormulaAndFunctionResponseFormat,
110                > = None;
111                let mut additional_properties: std::collections::BTreeMap<
112                    String,
113                    serde_json::Value,
114                > = std::collections::BTreeMap::new();
115                let mut _unparsed = false;
116
117                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
118                    match k.as_str() {
119                        "formulas" => {
120                            if v.is_null() {
121                                continue;
122                            }
123                            formulas = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
124                        }
125                        "q" => {
126                            if v.is_null() {
127                                continue;
128                            }
129                            q = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
130                        }
131                        "queries" => {
132                            if v.is_null() {
133                                continue;
134                            }
135                            queries = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
136                        }
137                        "response_format" => {
138                            if v.is_null() {
139                                continue;
140                            }
141                            response_format =
142                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
143                            if let Some(ref _response_format) = response_format {
144                                match _response_format {
145                                    crate::datadogV1::model::FormulaAndFunctionResponseFormat::UnparsedObject(_response_format) => {
146                                        _unparsed = true;
147                                    },
148                                    _ => {}
149                                }
150                            }
151                        }
152                        &_ => {
153                            if let Ok(value) = serde_json::from_value(v.clone()) {
154                                additional_properties.insert(k, value);
155                            }
156                        }
157                    }
158                }
159
160                let content = TreeMapWidgetRequest {
161                    formulas,
162                    q,
163                    queries,
164                    response_format,
165                    additional_properties,
166                    _unparsed,
167                };
168
169                Ok(content)
170            }
171        }
172
173        deserializer.deserialize_any(TreeMapWidgetRequestVisitor)
174    }
175}