datadog_api_client/datadogV1/model/
model_scatterplot_table_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/// Scatterplot request containing formulas and functions.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ScatterplotTableRequest {
14    /// List of Scatterplot formulas that operate on queries.
15    #[serde(rename = "formulas")]
16    pub formulas: Option<Vec<crate::datadogV1::model::ScatterplotWidgetFormula>>,
17    /// List of queries that can be returned directly or used in formulas.
18    #[serde(rename = "queries")]
19    pub queries: Option<Vec<crate::datadogV1::model::FormulaAndFunctionQueryDefinition>>,
20    /// Timeseries, scalar, or event list response. Event list response formats are supported by Geomap widgets.
21    #[serde(rename = "response_format")]
22    pub response_format: Option<crate::datadogV1::model::FormulaAndFunctionResponseFormat>,
23    #[serde(flatten)]
24    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25    #[serde(skip)]
26    #[serde(default)]
27    pub(crate) _unparsed: bool,
28}
29
30impl ScatterplotTableRequest {
31    pub fn new() -> ScatterplotTableRequest {
32        ScatterplotTableRequest {
33            formulas: None,
34            queries: None,
35            response_format: None,
36            additional_properties: std::collections::BTreeMap::new(),
37            _unparsed: false,
38        }
39    }
40
41    pub fn formulas(
42        mut self,
43        value: Vec<crate::datadogV1::model::ScatterplotWidgetFormula>,
44    ) -> Self {
45        self.formulas = Some(value);
46        self
47    }
48
49    pub fn queries(
50        mut self,
51        value: Vec<crate::datadogV1::model::FormulaAndFunctionQueryDefinition>,
52    ) -> Self {
53        self.queries = Some(value);
54        self
55    }
56
57    pub fn response_format(
58        mut self,
59        value: crate::datadogV1::model::FormulaAndFunctionResponseFormat,
60    ) -> Self {
61        self.response_format = Some(value);
62        self
63    }
64
65    pub fn additional_properties(
66        mut self,
67        value: std::collections::BTreeMap<String, serde_json::Value>,
68    ) -> Self {
69        self.additional_properties = value;
70        self
71    }
72}
73
74impl Default for ScatterplotTableRequest {
75    fn default() -> Self {
76        Self::new()
77    }
78}
79
80impl<'de> Deserialize<'de> for ScatterplotTableRequest {
81    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
82    where
83        D: Deserializer<'de>,
84    {
85        struct ScatterplotTableRequestVisitor;
86        impl<'a> Visitor<'a> for ScatterplotTableRequestVisitor {
87            type Value = ScatterplotTableRequest;
88
89            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
90                f.write_str("a mapping")
91            }
92
93            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
94            where
95                M: MapAccess<'a>,
96            {
97                let mut formulas: Option<Vec<crate::datadogV1::model::ScatterplotWidgetFormula>> =
98                    None;
99                let mut queries: Option<
100                    Vec<crate::datadogV1::model::FormulaAndFunctionQueryDefinition>,
101                > = None;
102                let mut response_format: Option<
103                    crate::datadogV1::model::FormulaAndFunctionResponseFormat,
104                > = None;
105                let mut additional_properties: std::collections::BTreeMap<
106                    String,
107                    serde_json::Value,
108                > = std::collections::BTreeMap::new();
109                let mut _unparsed = false;
110
111                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
112                    match k.as_str() {
113                        "formulas" => {
114                            if v.is_null() {
115                                continue;
116                            }
117                            formulas = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
118                        }
119                        "queries" => {
120                            if v.is_null() {
121                                continue;
122                            }
123                            queries = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
124                        }
125                        "response_format" => {
126                            if v.is_null() {
127                                continue;
128                            }
129                            response_format =
130                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
131                            if let Some(ref _response_format) = response_format {
132                                match _response_format {
133                                    crate::datadogV1::model::FormulaAndFunctionResponseFormat::UnparsedObject(_response_format) => {
134                                        _unparsed = true;
135                                    },
136                                    _ => {}
137                                }
138                            }
139                        }
140                        &_ => {
141                            if let Ok(value) = serde_json::from_value(v.clone()) {
142                                additional_properties.insert(k, value);
143                            }
144                        }
145                    }
146                }
147
148                let content = ScatterplotTableRequest {
149                    formulas,
150                    queries,
151                    response_format,
152                    additional_properties,
153                    _unparsed,
154                };
155
156                Ok(content)
157            }
158        }
159
160        deserializer.deserialize_any(ScatterplotTableRequestVisitor)
161    }
162}