datadog_api_client/datadogV1/model/
model_synthetics_config_variable.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct SyntheticsConfigVariable {
14 #[serde(rename = "example")]
16 pub example: Option<String>,
17 #[serde(rename = "id")]
19 pub id: Option<String>,
20 #[serde(rename = "name")]
22 pub name: String,
23 #[serde(rename = "pattern")]
25 pub pattern: Option<String>,
26 #[serde(rename = "secure")]
28 pub secure: Option<bool>,
29 #[serde(rename = "type")]
31 pub type_: crate::datadogV1::model::SyntheticsConfigVariableType,
32 #[serde(flatten)]
33 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
34 #[serde(skip)]
35 #[serde(default)]
36 pub(crate) _unparsed: bool,
37}
38
39impl SyntheticsConfigVariable {
40 pub fn new(
41 name: String,
42 type_: crate::datadogV1::model::SyntheticsConfigVariableType,
43 ) -> SyntheticsConfigVariable {
44 SyntheticsConfigVariable {
45 example: None,
46 id: None,
47 name,
48 pattern: None,
49 secure: None,
50 type_,
51 additional_properties: std::collections::BTreeMap::new(),
52 _unparsed: false,
53 }
54 }
55
56 pub fn example(mut self, value: String) -> Self {
57 self.example = Some(value);
58 self
59 }
60
61 pub fn id(mut self, value: String) -> Self {
62 self.id = Some(value);
63 self
64 }
65
66 pub fn pattern(mut self, value: String) -> Self {
67 self.pattern = Some(value);
68 self
69 }
70
71 pub fn secure(mut self, value: bool) -> Self {
72 self.secure = Some(value);
73 self
74 }
75
76 pub fn additional_properties(
77 mut self,
78 value: std::collections::BTreeMap<String, serde_json::Value>,
79 ) -> Self {
80 self.additional_properties = value;
81 self
82 }
83}
84
85impl<'de> Deserialize<'de> for SyntheticsConfigVariable {
86 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
87 where
88 D: Deserializer<'de>,
89 {
90 struct SyntheticsConfigVariableVisitor;
91 impl<'a> Visitor<'a> for SyntheticsConfigVariableVisitor {
92 type Value = SyntheticsConfigVariable;
93
94 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
95 f.write_str("a mapping")
96 }
97
98 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
99 where
100 M: MapAccess<'a>,
101 {
102 let mut example: Option<String> = None;
103 let mut id: Option<String> = None;
104 let mut name: Option<String> = None;
105 let mut pattern: Option<String> = None;
106 let mut secure: Option<bool> = None;
107 let mut type_: Option<crate::datadogV1::model::SyntheticsConfigVariableType> = None;
108 let mut additional_properties: std::collections::BTreeMap<
109 String,
110 serde_json::Value,
111 > = std::collections::BTreeMap::new();
112 let mut _unparsed = false;
113
114 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
115 match k.as_str() {
116 "example" => {
117 if v.is_null() {
118 continue;
119 }
120 example = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
121 }
122 "id" => {
123 if v.is_null() {
124 continue;
125 }
126 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
127 }
128 "name" => {
129 name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
130 }
131 "pattern" => {
132 if v.is_null() {
133 continue;
134 }
135 pattern = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
136 }
137 "secure" => {
138 if v.is_null() {
139 continue;
140 }
141 secure = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
142 }
143 "type" => {
144 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
145 if let Some(ref _type_) = type_ {
146 match _type_ {
147 crate::datadogV1::model::SyntheticsConfigVariableType::UnparsedObject(_type_) => {
148 _unparsed = true;
149 },
150 _ => {}
151 }
152 }
153 }
154 &_ => {
155 if let Ok(value) = serde_json::from_value(v.clone()) {
156 additional_properties.insert(k, value);
157 }
158 }
159 }
160 }
161 let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
162 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
163
164 let content = SyntheticsConfigVariable {
165 example,
166 id,
167 name,
168 pattern,
169 secure,
170 type_,
171 additional_properties,
172 _unparsed,
173 };
174
175 Ok(content)
176 }
177 }
178
179 deserializer.deserialize_any(SyntheticsConfigVariableVisitor)
180 }
181}