datadog_api_client/datadogV1/model/
model_synthetics_browser_test.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 details about a Synthetic browser test.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct SyntheticsBrowserTest {
14    /// Configuration object for a Synthetic browser test.
15    #[serde(rename = "config")]
16    pub config: crate::datadogV1::model::SyntheticsBrowserTestConfig,
17    /// Array of locations used to run the test.
18    #[serde(rename = "locations")]
19    pub locations: Vec<String>,
20    /// Notification message associated with the test. Message can either be text or an empty string.
21    #[serde(rename = "message")]
22    pub message: String,
23    /// The associated monitor ID.
24    #[serde(rename = "monitor_id")]
25    pub monitor_id: Option<i64>,
26    /// Name of the test.
27    #[serde(rename = "name")]
28    pub name: String,
29    /// Object describing the extra options for a Synthetic test.
30    #[serde(rename = "options")]
31    pub options: crate::datadogV1::model::SyntheticsTestOptions,
32    /// The public ID of the test.
33    #[serde(rename = "public_id")]
34    pub public_id: Option<String>,
35    /// Define whether you want to start (`live`) or pause (`paused`) a
36    /// Synthetic test.
37    #[serde(rename = "status")]
38    pub status: Option<crate::datadogV1::model::SyntheticsTestPauseStatus>,
39    /// Array of steps for the test.
40    #[serde(rename = "steps")]
41    pub steps: Option<Vec<crate::datadogV1::model::SyntheticsStep>>,
42    /// Array of tags attached to the test.
43    #[serde(rename = "tags")]
44    pub tags: Option<Vec<String>>,
45    /// Type of the Synthetic test, `browser`.
46    #[serde(rename = "type")]
47    pub type_: crate::datadogV1::model::SyntheticsBrowserTestType,
48    #[serde(flatten)]
49    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
50    #[serde(skip)]
51    #[serde(default)]
52    pub(crate) _unparsed: bool,
53}
54
55impl SyntheticsBrowserTest {
56    pub fn new(
57        config: crate::datadogV1::model::SyntheticsBrowserTestConfig,
58        locations: Vec<String>,
59        message: String,
60        name: String,
61        options: crate::datadogV1::model::SyntheticsTestOptions,
62        type_: crate::datadogV1::model::SyntheticsBrowserTestType,
63    ) -> SyntheticsBrowserTest {
64        SyntheticsBrowserTest {
65            config,
66            locations,
67            message,
68            monitor_id: None,
69            name,
70            options,
71            public_id: None,
72            status: None,
73            steps: None,
74            tags: None,
75            type_,
76            additional_properties: std::collections::BTreeMap::new(),
77            _unparsed: false,
78        }
79    }
80
81    pub fn monitor_id(mut self, value: i64) -> Self {
82        self.monitor_id = Some(value);
83        self
84    }
85
86    pub fn public_id(mut self, value: String) -> Self {
87        self.public_id = Some(value);
88        self
89    }
90
91    pub fn status(mut self, value: crate::datadogV1::model::SyntheticsTestPauseStatus) -> Self {
92        self.status = Some(value);
93        self
94    }
95
96    pub fn steps(mut self, value: Vec<crate::datadogV1::model::SyntheticsStep>) -> Self {
97        self.steps = Some(value);
98        self
99    }
100
101    pub fn tags(mut self, value: Vec<String>) -> Self {
102        self.tags = Some(value);
103        self
104    }
105
106    pub fn additional_properties(
107        mut self,
108        value: std::collections::BTreeMap<String, serde_json::Value>,
109    ) -> Self {
110        self.additional_properties = value;
111        self
112    }
113}
114
115impl<'de> Deserialize<'de> for SyntheticsBrowserTest {
116    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
117    where
118        D: Deserializer<'de>,
119    {
120        struct SyntheticsBrowserTestVisitor;
121        impl<'a> Visitor<'a> for SyntheticsBrowserTestVisitor {
122            type Value = SyntheticsBrowserTest;
123
124            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
125                f.write_str("a mapping")
126            }
127
128            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
129            where
130                M: MapAccess<'a>,
131            {
132                let mut config: Option<crate::datadogV1::model::SyntheticsBrowserTestConfig> = None;
133                let mut locations: Option<Vec<String>> = None;
134                let mut message: Option<String> = None;
135                let mut monitor_id: Option<i64> = None;
136                let mut name: Option<String> = None;
137                let mut options: Option<crate::datadogV1::model::SyntheticsTestOptions> = None;
138                let mut public_id: Option<String> = None;
139                let mut status: Option<crate::datadogV1::model::SyntheticsTestPauseStatus> = None;
140                let mut steps: Option<Vec<crate::datadogV1::model::SyntheticsStep>> = None;
141                let mut tags: Option<Vec<String>> = None;
142                let mut type_: Option<crate::datadogV1::model::SyntheticsBrowserTestType> = None;
143                let mut additional_properties: std::collections::BTreeMap<
144                    String,
145                    serde_json::Value,
146                > = std::collections::BTreeMap::new();
147                let mut _unparsed = false;
148
149                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
150                    match k.as_str() {
151                        "config" => {
152                            config = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
153                        }
154                        "locations" => {
155                            locations = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
156                        }
157                        "message" => {
158                            message = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
159                        }
160                        "monitor_id" => {
161                            if v.is_null() {
162                                continue;
163                            }
164                            monitor_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
165                        }
166                        "name" => {
167                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
168                        }
169                        "options" => {
170                            options = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
171                        }
172                        "public_id" => {
173                            if v.is_null() {
174                                continue;
175                            }
176                            public_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
177                        }
178                        "status" => {
179                            if v.is_null() {
180                                continue;
181                            }
182                            status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
183                            if let Some(ref _status) = status {
184                                match _status {
185                                    crate::datadogV1::model::SyntheticsTestPauseStatus::UnparsedObject(_status) => {
186                                        _unparsed = true;
187                                    },
188                                    _ => {}
189                                }
190                            }
191                        }
192                        "steps" => {
193                            if v.is_null() {
194                                continue;
195                            }
196                            steps = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
197                        }
198                        "tags" => {
199                            if v.is_null() {
200                                continue;
201                            }
202                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
203                        }
204                        "type" => {
205                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
206                            if let Some(ref _type_) = type_ {
207                                match _type_ {
208                                    crate::datadogV1::model::SyntheticsBrowserTestType::UnparsedObject(_type_) => {
209                                        _unparsed = true;
210                                    },
211                                    _ => {}
212                                }
213                            }
214                        }
215                        &_ => {
216                            if let Ok(value) = serde_json::from_value(v.clone()) {
217                                additional_properties.insert(k, value);
218                            }
219                        }
220                    }
221                }
222                let config = config.ok_or_else(|| M::Error::missing_field("config"))?;
223                let locations = locations.ok_or_else(|| M::Error::missing_field("locations"))?;
224                let message = message.ok_or_else(|| M::Error::missing_field("message"))?;
225                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
226                let options = options.ok_or_else(|| M::Error::missing_field("options"))?;
227                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
228
229                let content = SyntheticsBrowserTest {
230                    config,
231                    locations,
232                    message,
233                    monitor_id,
234                    name,
235                    options,
236                    public_id,
237                    status,
238                    steps,
239                    tags,
240                    type_,
241                    additional_properties,
242                    _unparsed,
243                };
244
245                Ok(content)
246            }
247        }
248
249        deserializer.deserialize_any(SyntheticsBrowserTestVisitor)
250    }
251}