datadog_api_client/datadogV1/model/
model_table_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/// Updated table widget.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct TableWidgetRequest {
14    /// Aggregator used for the request.
15    #[serde(rename = "aggregator")]
16    pub aggregator: Option<crate::datadogV1::model::WidgetAggregator>,
17    /// The column name (defaults to the metric name).
18    #[serde(rename = "alias")]
19    pub alias: Option<String>,
20    /// The log query.
21    #[serde(rename = "apm_query")]
22    pub apm_query: Option<crate::datadogV1::model::LogQueryDefinition>,
23    /// The APM stats query for table and distributions widgets.
24    #[serde(rename = "apm_stats_query")]
25    pub apm_stats_query: Option<crate::datadogV1::model::ApmStatsQueryDefinition>,
26    /// A list of display modes for each table cell.
27    #[serde(rename = "cell_display_mode")]
28    pub cell_display_mode: Option<Vec<crate::datadogV1::model::TableWidgetCellDisplayMode>>,
29    /// List of conditional formats.
30    #[serde(rename = "conditional_formats")]
31    pub conditional_formats: Option<Vec<crate::datadogV1::model::WidgetConditionalFormat>>,
32    /// The log query.
33    #[serde(rename = "event_query")]
34    pub event_query: Option<crate::datadogV1::model::LogQueryDefinition>,
35    /// List of formulas that operate on queries.
36    #[serde(rename = "formulas")]
37    pub formulas: Option<Vec<crate::datadogV1::model::WidgetFormula>>,
38    /// For metric queries, the number of lines to show in the table. Only one request should have this property.
39    #[serde(rename = "limit")]
40    pub limit: Option<i64>,
41    /// The log query.
42    #[serde(rename = "log_query")]
43    pub log_query: Option<crate::datadogV1::model::LogQueryDefinition>,
44    /// The log query.
45    #[serde(rename = "network_query")]
46    pub network_query: Option<crate::datadogV1::model::LogQueryDefinition>,
47    /// Widget sorting methods.
48    #[serde(rename = "order")]
49    pub order: Option<crate::datadogV1::model::WidgetSort>,
50    /// The process query to use in the widget.
51    #[serde(rename = "process_query")]
52    pub process_query: Option<crate::datadogV1::model::ProcessQueryDefinition>,
53    /// The log query.
54    #[serde(rename = "profile_metrics_query")]
55    pub profile_metrics_query: Option<crate::datadogV1::model::LogQueryDefinition>,
56    /// Query definition.
57    #[serde(rename = "q")]
58    pub q: Option<String>,
59    /// List of queries that can be returned directly or used in formulas.
60    #[serde(rename = "queries")]
61    pub queries: Option<Vec<crate::datadogV1::model::FormulaAndFunctionQueryDefinition>>,
62    /// Timeseries, scalar, or event list response. Event list response formats are supported by Geomap widgets.
63    #[serde(rename = "response_format")]
64    pub response_format: Option<crate::datadogV1::model::FormulaAndFunctionResponseFormat>,
65    /// The log query.
66    #[serde(rename = "rum_query")]
67    pub rum_query: Option<crate::datadogV1::model::LogQueryDefinition>,
68    /// The log query.
69    #[serde(rename = "security_query")]
70    pub security_query: Option<crate::datadogV1::model::LogQueryDefinition>,
71    /// The controls for sorting the widget.
72    #[serde(rename = "sort")]
73    pub sort: Option<crate::datadogV1::model::WidgetSortBy>,
74    /// List of text formats for columns produced by tags.
75    #[serde(rename = "text_formats")]
76    pub text_formats: Option<Vec<Vec<crate::datadogV1::model::TableWidgetTextFormatRule>>>,
77    #[serde(flatten)]
78    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
79    #[serde(skip)]
80    #[serde(default)]
81    pub(crate) _unparsed: bool,
82}
83
84impl TableWidgetRequest {
85    pub fn new() -> TableWidgetRequest {
86        TableWidgetRequest {
87            aggregator: None,
88            alias: None,
89            apm_query: None,
90            apm_stats_query: None,
91            cell_display_mode: None,
92            conditional_formats: None,
93            event_query: None,
94            formulas: None,
95            limit: None,
96            log_query: None,
97            network_query: None,
98            order: None,
99            process_query: None,
100            profile_metrics_query: None,
101            q: None,
102            queries: None,
103            response_format: None,
104            rum_query: None,
105            security_query: None,
106            sort: None,
107            text_formats: None,
108            additional_properties: std::collections::BTreeMap::new(),
109            _unparsed: false,
110        }
111    }
112
113    pub fn aggregator(mut self, value: crate::datadogV1::model::WidgetAggregator) -> Self {
114        self.aggregator = Some(value);
115        self
116    }
117
118    pub fn alias(mut self, value: String) -> Self {
119        self.alias = Some(value);
120        self
121    }
122
123    pub fn apm_query(mut self, value: crate::datadogV1::model::LogQueryDefinition) -> Self {
124        self.apm_query = Some(value);
125        self
126    }
127
128    pub fn apm_stats_query(
129        mut self,
130        value: crate::datadogV1::model::ApmStatsQueryDefinition,
131    ) -> Self {
132        self.apm_stats_query = Some(value);
133        self
134    }
135
136    pub fn cell_display_mode(
137        mut self,
138        value: Vec<crate::datadogV1::model::TableWidgetCellDisplayMode>,
139    ) -> Self {
140        self.cell_display_mode = Some(value);
141        self
142    }
143
144    pub fn conditional_formats(
145        mut self,
146        value: Vec<crate::datadogV1::model::WidgetConditionalFormat>,
147    ) -> Self {
148        self.conditional_formats = Some(value);
149        self
150    }
151
152    pub fn event_query(mut self, value: crate::datadogV1::model::LogQueryDefinition) -> Self {
153        self.event_query = Some(value);
154        self
155    }
156
157    pub fn formulas(mut self, value: Vec<crate::datadogV1::model::WidgetFormula>) -> Self {
158        self.formulas = Some(value);
159        self
160    }
161
162    pub fn limit(mut self, value: i64) -> Self {
163        self.limit = Some(value);
164        self
165    }
166
167    pub fn log_query(mut self, value: crate::datadogV1::model::LogQueryDefinition) -> Self {
168        self.log_query = Some(value);
169        self
170    }
171
172    pub fn network_query(mut self, value: crate::datadogV1::model::LogQueryDefinition) -> Self {
173        self.network_query = Some(value);
174        self
175    }
176
177    pub fn order(mut self, value: crate::datadogV1::model::WidgetSort) -> Self {
178        self.order = Some(value);
179        self
180    }
181
182    pub fn process_query(mut self, value: crate::datadogV1::model::ProcessQueryDefinition) -> Self {
183        self.process_query = Some(value);
184        self
185    }
186
187    pub fn profile_metrics_query(
188        mut self,
189        value: crate::datadogV1::model::LogQueryDefinition,
190    ) -> Self {
191        self.profile_metrics_query = Some(value);
192        self
193    }
194
195    pub fn q(mut self, value: String) -> Self {
196        self.q = Some(value);
197        self
198    }
199
200    pub fn queries(
201        mut self,
202        value: Vec<crate::datadogV1::model::FormulaAndFunctionQueryDefinition>,
203    ) -> Self {
204        self.queries = Some(value);
205        self
206    }
207
208    pub fn response_format(
209        mut self,
210        value: crate::datadogV1::model::FormulaAndFunctionResponseFormat,
211    ) -> Self {
212        self.response_format = Some(value);
213        self
214    }
215
216    pub fn rum_query(mut self, value: crate::datadogV1::model::LogQueryDefinition) -> Self {
217        self.rum_query = Some(value);
218        self
219    }
220
221    pub fn security_query(mut self, value: crate::datadogV1::model::LogQueryDefinition) -> Self {
222        self.security_query = Some(value);
223        self
224    }
225
226    pub fn sort(mut self, value: crate::datadogV1::model::WidgetSortBy) -> Self {
227        self.sort = Some(value);
228        self
229    }
230
231    pub fn text_formats(
232        mut self,
233        value: Vec<Vec<crate::datadogV1::model::TableWidgetTextFormatRule>>,
234    ) -> Self {
235        self.text_formats = Some(value);
236        self
237    }
238
239    pub fn additional_properties(
240        mut self,
241        value: std::collections::BTreeMap<String, serde_json::Value>,
242    ) -> Self {
243        self.additional_properties = value;
244        self
245    }
246}
247
248impl Default for TableWidgetRequest {
249    fn default() -> Self {
250        Self::new()
251    }
252}
253
254impl<'de> Deserialize<'de> for TableWidgetRequest {
255    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
256    where
257        D: Deserializer<'de>,
258    {
259        struct TableWidgetRequestVisitor;
260        impl<'a> Visitor<'a> for TableWidgetRequestVisitor {
261            type Value = TableWidgetRequest;
262
263            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
264                f.write_str("a mapping")
265            }
266
267            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
268            where
269                M: MapAccess<'a>,
270            {
271                let mut aggregator: Option<crate::datadogV1::model::WidgetAggregator> = None;
272                let mut alias: Option<String> = None;
273                let mut apm_query: Option<crate::datadogV1::model::LogQueryDefinition> = None;
274                let mut apm_stats_query: Option<crate::datadogV1::model::ApmStatsQueryDefinition> =
275                    None;
276                let mut cell_display_mode: Option<
277                    Vec<crate::datadogV1::model::TableWidgetCellDisplayMode>,
278                > = None;
279                let mut conditional_formats: Option<
280                    Vec<crate::datadogV1::model::WidgetConditionalFormat>,
281                > = None;
282                let mut event_query: Option<crate::datadogV1::model::LogQueryDefinition> = None;
283                let mut formulas: Option<Vec<crate::datadogV1::model::WidgetFormula>> = None;
284                let mut limit: Option<i64> = None;
285                let mut log_query: Option<crate::datadogV1::model::LogQueryDefinition> = None;
286                let mut network_query: Option<crate::datadogV1::model::LogQueryDefinition> = None;
287                let mut order: Option<crate::datadogV1::model::WidgetSort> = None;
288                let mut process_query: Option<crate::datadogV1::model::ProcessQueryDefinition> =
289                    None;
290                let mut profile_metrics_query: Option<crate::datadogV1::model::LogQueryDefinition> =
291                    None;
292                let mut q: Option<String> = None;
293                let mut queries: Option<
294                    Vec<crate::datadogV1::model::FormulaAndFunctionQueryDefinition>,
295                > = None;
296                let mut response_format: Option<
297                    crate::datadogV1::model::FormulaAndFunctionResponseFormat,
298                > = None;
299                let mut rum_query: Option<crate::datadogV1::model::LogQueryDefinition> = None;
300                let mut security_query: Option<crate::datadogV1::model::LogQueryDefinition> = None;
301                let mut sort: Option<crate::datadogV1::model::WidgetSortBy> = None;
302                let mut text_formats: Option<
303                    Vec<Vec<crate::datadogV1::model::TableWidgetTextFormatRule>>,
304                > = None;
305                let mut additional_properties: std::collections::BTreeMap<
306                    String,
307                    serde_json::Value,
308                > = std::collections::BTreeMap::new();
309                let mut _unparsed = false;
310
311                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
312                    match k.as_str() {
313                        "aggregator" => {
314                            if v.is_null() {
315                                continue;
316                            }
317                            aggregator = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
318                            if let Some(ref _aggregator) = aggregator {
319                                match _aggregator {
320                                    crate::datadogV1::model::WidgetAggregator::UnparsedObject(
321                                        _aggregator,
322                                    ) => {
323                                        _unparsed = true;
324                                    }
325                                    _ => {}
326                                }
327                            }
328                        }
329                        "alias" => {
330                            if v.is_null() {
331                                continue;
332                            }
333                            alias = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
334                        }
335                        "apm_query" => {
336                            if v.is_null() {
337                                continue;
338                            }
339                            apm_query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
340                        }
341                        "apm_stats_query" => {
342                            if v.is_null() {
343                                continue;
344                            }
345                            apm_stats_query =
346                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
347                        }
348                        "cell_display_mode" => {
349                            if v.is_null() {
350                                continue;
351                            }
352                            cell_display_mode =
353                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
354                        }
355                        "conditional_formats" => {
356                            if v.is_null() {
357                                continue;
358                            }
359                            conditional_formats =
360                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
361                        }
362                        "event_query" => {
363                            if v.is_null() {
364                                continue;
365                            }
366                            event_query =
367                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
368                        }
369                        "formulas" => {
370                            if v.is_null() {
371                                continue;
372                            }
373                            formulas = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
374                        }
375                        "limit" => {
376                            if v.is_null() {
377                                continue;
378                            }
379                            limit = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
380                        }
381                        "log_query" => {
382                            if v.is_null() {
383                                continue;
384                            }
385                            log_query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
386                        }
387                        "network_query" => {
388                            if v.is_null() {
389                                continue;
390                            }
391                            network_query =
392                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
393                        }
394                        "order" => {
395                            if v.is_null() {
396                                continue;
397                            }
398                            order = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
399                            if let Some(ref _order) = order {
400                                match _order {
401                                    crate::datadogV1::model::WidgetSort::UnparsedObject(_order) => {
402                                        _unparsed = true;
403                                    }
404                                    _ => {}
405                                }
406                            }
407                        }
408                        "process_query" => {
409                            if v.is_null() {
410                                continue;
411                            }
412                            process_query =
413                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
414                        }
415                        "profile_metrics_query" => {
416                            if v.is_null() {
417                                continue;
418                            }
419                            profile_metrics_query =
420                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
421                        }
422                        "q" => {
423                            if v.is_null() {
424                                continue;
425                            }
426                            q = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
427                        }
428                        "queries" => {
429                            if v.is_null() {
430                                continue;
431                            }
432                            queries = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
433                        }
434                        "response_format" => {
435                            if v.is_null() {
436                                continue;
437                            }
438                            response_format =
439                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
440                            if let Some(ref _response_format) = response_format {
441                                match _response_format {
442                                    crate::datadogV1::model::FormulaAndFunctionResponseFormat::UnparsedObject(_response_format) => {
443                                        _unparsed = true;
444                                    },
445                                    _ => {}
446                                }
447                            }
448                        }
449                        "rum_query" => {
450                            if v.is_null() {
451                                continue;
452                            }
453                            rum_query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
454                        }
455                        "security_query" => {
456                            if v.is_null() {
457                                continue;
458                            }
459                            security_query =
460                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
461                        }
462                        "sort" => {
463                            if v.is_null() {
464                                continue;
465                            }
466                            sort = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
467                        }
468                        "text_formats" => {
469                            if v.is_null() {
470                                continue;
471                            }
472                            text_formats =
473                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
474                        }
475                        &_ => {
476                            if let Ok(value) = serde_json::from_value(v.clone()) {
477                                additional_properties.insert(k, value);
478                            }
479                        }
480                    }
481                }
482
483                let content = TableWidgetRequest {
484                    aggregator,
485                    alias,
486                    apm_query,
487                    apm_stats_query,
488                    cell_display_mode,
489                    conditional_formats,
490                    event_query,
491                    formulas,
492                    limit,
493                    log_query,
494                    network_query,
495                    order,
496                    process_query,
497                    profile_metrics_query,
498                    q,
499                    queries,
500                    response_format,
501                    rum_query,
502                    security_query,
503                    sort,
504                    text_formats,
505                    additional_properties,
506                    _unparsed,
507                };
508
509                Ok(content)
510            }
511        }
512
513        deserializer.deserialize_any(TableWidgetRequestVisitor)
514    }
515}