datadog_api_client/datadogV1/model/
model_service_level_objective_request.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]
12#[skip_serializing_none]
13#[derive(Clone, Debug, PartialEq, Serialize)]
14pub struct ServiceLevelObjectiveRequest {
15 #[serde(
20 rename = "description",
21 default,
22 with = "::serde_with::rust::double_option"
23 )]
24 pub description: Option<Option<String>>,
25 #[serde(rename = "groups")]
31 pub groups: Option<Vec<String>>,
32 #[serde(rename = "monitor_ids")]
35 pub monitor_ids: Option<Vec<i64>>,
36 #[serde(rename = "name")]
38 pub name: String,
39 #[serde(rename = "query")]
43 pub query: Option<crate::datadogV1::model::ServiceLevelObjectiveQuery>,
44 #[serde(rename = "sli_specification")]
46 pub sli_specification: Option<crate::datadogV1::model::SLOSliSpec>,
47 #[serde(rename = "tags")]
51 pub tags: Option<Vec<String>>,
52 #[serde(rename = "target_threshold")]
55 pub target_threshold: Option<f64>,
56 #[serde(rename = "thresholds")]
59 pub thresholds: Vec<crate::datadogV1::model::SLOThreshold>,
60 #[serde(rename = "timeframe")]
63 pub timeframe: Option<crate::datadogV1::model::SLOTimeframe>,
64 #[serde(rename = "type")]
66 pub type_: crate::datadogV1::model::SLOType,
67 #[serde(rename = "warning_threshold")]
72 pub warning_threshold: Option<f64>,
73 #[serde(flatten)]
74 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
75 #[serde(skip)]
76 #[serde(default)]
77 pub(crate) _unparsed: bool,
78}
79
80impl ServiceLevelObjectiveRequest {
81 pub fn new(
82 name: String,
83 thresholds: Vec<crate::datadogV1::model::SLOThreshold>,
84 type_: crate::datadogV1::model::SLOType,
85 ) -> ServiceLevelObjectiveRequest {
86 ServiceLevelObjectiveRequest {
87 description: None,
88 groups: None,
89 monitor_ids: None,
90 name,
91 query: None,
92 sli_specification: None,
93 tags: None,
94 target_threshold: None,
95 thresholds,
96 timeframe: None,
97 type_,
98 warning_threshold: None,
99 additional_properties: std::collections::BTreeMap::new(),
100 _unparsed: false,
101 }
102 }
103
104 pub fn description(mut self, value: Option<String>) -> Self {
105 self.description = Some(value);
106 self
107 }
108
109 pub fn groups(mut self, value: Vec<String>) -> Self {
110 self.groups = Some(value);
111 self
112 }
113
114 pub fn monitor_ids(mut self, value: Vec<i64>) -> Self {
115 self.monitor_ids = Some(value);
116 self
117 }
118
119 pub fn query(mut self, value: crate::datadogV1::model::ServiceLevelObjectiveQuery) -> Self {
120 self.query = Some(value);
121 self
122 }
123
124 pub fn sli_specification(mut self, value: crate::datadogV1::model::SLOSliSpec) -> Self {
125 self.sli_specification = Some(value);
126 self
127 }
128
129 pub fn tags(mut self, value: Vec<String>) -> Self {
130 self.tags = Some(value);
131 self
132 }
133
134 pub fn target_threshold(mut self, value: f64) -> Self {
135 self.target_threshold = Some(value);
136 self
137 }
138
139 pub fn timeframe(mut self, value: crate::datadogV1::model::SLOTimeframe) -> Self {
140 self.timeframe = Some(value);
141 self
142 }
143
144 pub fn warning_threshold(mut self, value: f64) -> Self {
145 self.warning_threshold = Some(value);
146 self
147 }
148
149 pub fn additional_properties(
150 mut self,
151 value: std::collections::BTreeMap<String, serde_json::Value>,
152 ) -> Self {
153 self.additional_properties = value;
154 self
155 }
156}
157
158impl<'de> Deserialize<'de> for ServiceLevelObjectiveRequest {
159 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
160 where
161 D: Deserializer<'de>,
162 {
163 struct ServiceLevelObjectiveRequestVisitor;
164 impl<'a> Visitor<'a> for ServiceLevelObjectiveRequestVisitor {
165 type Value = ServiceLevelObjectiveRequest;
166
167 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
168 f.write_str("a mapping")
169 }
170
171 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
172 where
173 M: MapAccess<'a>,
174 {
175 let mut description: Option<Option<String>> = None;
176 let mut groups: Option<Vec<String>> = None;
177 let mut monitor_ids: Option<Vec<i64>> = None;
178 let mut name: Option<String> = None;
179 let mut query: Option<crate::datadogV1::model::ServiceLevelObjectiveQuery> = None;
180 let mut sli_specification: Option<crate::datadogV1::model::SLOSliSpec> = None;
181 let mut tags: Option<Vec<String>> = None;
182 let mut target_threshold: Option<f64> = None;
183 let mut thresholds: Option<Vec<crate::datadogV1::model::SLOThreshold>> = None;
184 let mut timeframe: Option<crate::datadogV1::model::SLOTimeframe> = None;
185 let mut type_: Option<crate::datadogV1::model::SLOType> = None;
186 let mut warning_threshold: Option<f64> = None;
187 let mut additional_properties: std::collections::BTreeMap<
188 String,
189 serde_json::Value,
190 > = std::collections::BTreeMap::new();
191 let mut _unparsed = false;
192
193 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
194 match k.as_str() {
195 "description" => {
196 description =
197 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
198 }
199 "groups" => {
200 if v.is_null() {
201 continue;
202 }
203 groups = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
204 }
205 "monitor_ids" => {
206 if v.is_null() {
207 continue;
208 }
209 monitor_ids =
210 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
211 }
212 "name" => {
213 name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
214 }
215 "query" => {
216 if v.is_null() {
217 continue;
218 }
219 query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
220 }
221 "sli_specification" => {
222 if v.is_null() {
223 continue;
224 }
225 sli_specification =
226 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
227 if let Some(ref _sli_specification) = sli_specification {
228 match _sli_specification {
229 crate::datadogV1::model::SLOSliSpec::UnparsedObject(
230 _sli_specification,
231 ) => {
232 _unparsed = true;
233 }
234 _ => {}
235 }
236 }
237 }
238 "tags" => {
239 if v.is_null() {
240 continue;
241 }
242 tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
243 }
244 "target_threshold" => {
245 if v.is_null() {
246 continue;
247 }
248 target_threshold =
249 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
250 }
251 "thresholds" => {
252 thresholds = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
253 }
254 "timeframe" => {
255 if v.is_null() {
256 continue;
257 }
258 timeframe = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
259 if let Some(ref _timeframe) = timeframe {
260 match _timeframe {
261 crate::datadogV1::model::SLOTimeframe::UnparsedObject(
262 _timeframe,
263 ) => {
264 _unparsed = true;
265 }
266 _ => {}
267 }
268 }
269 }
270 "type" => {
271 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
272 if let Some(ref _type_) = type_ {
273 match _type_ {
274 crate::datadogV1::model::SLOType::UnparsedObject(_type_) => {
275 _unparsed = true;
276 }
277 _ => {}
278 }
279 }
280 }
281 "warning_threshold" => {
282 if v.is_null() {
283 continue;
284 }
285 warning_threshold =
286 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
287 }
288 &_ => {
289 if let Ok(value) = serde_json::from_value(v.clone()) {
290 additional_properties.insert(k, value);
291 }
292 }
293 }
294 }
295 let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
296 let thresholds = thresholds.ok_or_else(|| M::Error::missing_field("thresholds"))?;
297 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
298
299 let content = ServiceLevelObjectiveRequest {
300 description,
301 groups,
302 monitor_ids,
303 name,
304 query,
305 sli_specification,
306 tags,
307 target_threshold,
308 thresholds,
309 timeframe,
310 type_,
311 warning_threshold,
312 additional_properties,
313 _unparsed,
314 };
315
316 Ok(content)
317 }
318 }
319
320 deserializer.deserialize_any(ServiceLevelObjectiveRequestVisitor)
321 }
322}