datadog_api_client/datadogV1/model/
model_selectable_template_variable_items.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/// Object containing the template variable's name, associated tag/attribute, default value and selectable values.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct SelectableTemplateVariableItems {
14    /// The default value of the template variable.
15    #[serde(rename = "default_value")]
16    pub default_value: Option<String>,
17    /// Name of the template variable.
18    #[serde(rename = "name")]
19    pub name: Option<String>,
20    /// The tag/attribute key associated with the template variable.
21    #[serde(rename = "prefix")]
22    pub prefix: Option<String>,
23    /// The type of variable. This is to differentiate between filter variables (interpolated in query) and group by variables (interpolated into group by).
24    #[serde(rename = "type", default, with = "::serde_with::rust::double_option")]
25    pub type_: Option<Option<String>>,
26    /// List of visible tag values on the shared dashboard.
27    #[serde(
28        rename = "visible_tags",
29        default,
30        with = "::serde_with::rust::double_option"
31    )]
32    pub visible_tags: Option<Option<Vec<String>>>,
33    #[serde(flatten)]
34    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
35    #[serde(skip)]
36    #[serde(default)]
37    pub(crate) _unparsed: bool,
38}
39
40impl SelectableTemplateVariableItems {
41    pub fn new() -> SelectableTemplateVariableItems {
42        SelectableTemplateVariableItems {
43            default_value: None,
44            name: None,
45            prefix: None,
46            type_: None,
47            visible_tags: None,
48            additional_properties: std::collections::BTreeMap::new(),
49            _unparsed: false,
50        }
51    }
52
53    pub fn default_value(mut self, value: String) -> Self {
54        self.default_value = Some(value);
55        self
56    }
57
58    pub fn name(mut self, value: String) -> Self {
59        self.name = Some(value);
60        self
61    }
62
63    pub fn prefix(mut self, value: String) -> Self {
64        self.prefix = Some(value);
65        self
66    }
67
68    pub fn type_(mut self, value: Option<String>) -> Self {
69        self.type_ = Some(value);
70        self
71    }
72
73    pub fn visible_tags(mut self, value: Option<Vec<String>>) -> Self {
74        self.visible_tags = Some(value);
75        self
76    }
77
78    pub fn additional_properties(
79        mut self,
80        value: std::collections::BTreeMap<String, serde_json::Value>,
81    ) -> Self {
82        self.additional_properties = value;
83        self
84    }
85}
86
87impl Default for SelectableTemplateVariableItems {
88    fn default() -> Self {
89        Self::new()
90    }
91}
92
93impl<'de> Deserialize<'de> for SelectableTemplateVariableItems {
94    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
95    where
96        D: Deserializer<'de>,
97    {
98        struct SelectableTemplateVariableItemsVisitor;
99        impl<'a> Visitor<'a> for SelectableTemplateVariableItemsVisitor {
100            type Value = SelectableTemplateVariableItems;
101
102            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
103                f.write_str("a mapping")
104            }
105
106            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
107            where
108                M: MapAccess<'a>,
109            {
110                let mut default_value: Option<String> = None;
111                let mut name: Option<String> = None;
112                let mut prefix: Option<String> = None;
113                let mut type_: Option<Option<String>> = None;
114                let mut visible_tags: Option<Option<Vec<String>>> = None;
115                let mut additional_properties: std::collections::BTreeMap<
116                    String,
117                    serde_json::Value,
118                > = std::collections::BTreeMap::new();
119                let mut _unparsed = false;
120
121                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
122                    match k.as_str() {
123                        "default_value" => {
124                            if v.is_null() {
125                                continue;
126                            }
127                            default_value =
128                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
129                        }
130                        "name" => {
131                            if v.is_null() {
132                                continue;
133                            }
134                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
135                        }
136                        "prefix" => {
137                            if v.is_null() {
138                                continue;
139                            }
140                            prefix = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
141                        }
142                        "type" => {
143                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
144                        }
145                        "visible_tags" => {
146                            visible_tags =
147                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
148                        }
149                        &_ => {
150                            if let Ok(value) = serde_json::from_value(v.clone()) {
151                                additional_properties.insert(k, value);
152                            }
153                        }
154                    }
155                }
156
157                let content = SelectableTemplateVariableItems {
158                    default_value,
159                    name,
160                    prefix,
161                    type_,
162                    visible_tags,
163                    additional_properties,
164                    _unparsed,
165                };
166
167                Ok(content)
168            }
169        }
170
171        deserializer.deserialize_any(SelectableTemplateVariableItemsVisitor)
172    }
173}