datadog_api_client/datadogV1/model/
model_notebooks_response_data_attributes.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/// The attributes of a notebook in get all response.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct NotebooksResponseDataAttributes {
14    /// Attributes of user object returned by the API.
15    #[serde(rename = "author")]
16    pub author: Option<crate::datadogV1::model::NotebookAuthor>,
17    /// List of cells to display in the notebook.
18    #[serde(rename = "cells")]
19    pub cells: Option<Vec<crate::datadogV1::model::NotebookCellResponse>>,
20    /// UTC time stamp for when the notebook was created.
21    #[serde(rename = "created")]
22    pub created: Option<chrono::DateTime<chrono::Utc>>,
23    /// Metadata associated with the notebook.
24    #[serde(rename = "metadata")]
25    pub metadata: Option<crate::datadogV1::model::NotebookMetadata>,
26    /// UTC time stamp for when the notebook was last modified.
27    #[serde(rename = "modified")]
28    pub modified: Option<chrono::DateTime<chrono::Utc>>,
29    /// The name of the notebook.
30    #[serde(rename = "name")]
31    pub name: String,
32    /// Publication status of the notebook. For now, always "published".
33    #[serde(rename = "status")]
34    pub status: Option<crate::datadogV1::model::NotebookStatus>,
35    /// Notebook global timeframe.
36    #[serde(rename = "time")]
37    pub time: Option<crate::datadogV1::model::NotebookGlobalTime>,
38    #[serde(flatten)]
39    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
40    #[serde(skip)]
41    #[serde(default)]
42    pub(crate) _unparsed: bool,
43}
44
45impl NotebooksResponseDataAttributes {
46    pub fn new(name: String) -> NotebooksResponseDataAttributes {
47        NotebooksResponseDataAttributes {
48            author: None,
49            cells: None,
50            created: None,
51            metadata: None,
52            modified: None,
53            name,
54            status: None,
55            time: None,
56            additional_properties: std::collections::BTreeMap::new(),
57            _unparsed: false,
58        }
59    }
60
61    pub fn author(mut self, value: crate::datadogV1::model::NotebookAuthor) -> Self {
62        self.author = Some(value);
63        self
64    }
65
66    pub fn cells(mut self, value: Vec<crate::datadogV1::model::NotebookCellResponse>) -> Self {
67        self.cells = Some(value);
68        self
69    }
70
71    pub fn created(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
72        self.created = Some(value);
73        self
74    }
75
76    pub fn metadata(mut self, value: crate::datadogV1::model::NotebookMetadata) -> Self {
77        self.metadata = Some(value);
78        self
79    }
80
81    pub fn modified(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
82        self.modified = Some(value);
83        self
84    }
85
86    pub fn status(mut self, value: crate::datadogV1::model::NotebookStatus) -> Self {
87        self.status = Some(value);
88        self
89    }
90
91    pub fn time(mut self, value: crate::datadogV1::model::NotebookGlobalTime) -> Self {
92        self.time = Some(value);
93        self
94    }
95
96    pub fn additional_properties(
97        mut self,
98        value: std::collections::BTreeMap<String, serde_json::Value>,
99    ) -> Self {
100        self.additional_properties = value;
101        self
102    }
103}
104
105impl<'de> Deserialize<'de> for NotebooksResponseDataAttributes {
106    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
107    where
108        D: Deserializer<'de>,
109    {
110        struct NotebooksResponseDataAttributesVisitor;
111        impl<'a> Visitor<'a> for NotebooksResponseDataAttributesVisitor {
112            type Value = NotebooksResponseDataAttributes;
113
114            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
115                f.write_str("a mapping")
116            }
117
118            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
119            where
120                M: MapAccess<'a>,
121            {
122                let mut author: Option<crate::datadogV1::model::NotebookAuthor> = None;
123                let mut cells: Option<Vec<crate::datadogV1::model::NotebookCellResponse>> = None;
124                let mut created: Option<chrono::DateTime<chrono::Utc>> = None;
125                let mut metadata: Option<crate::datadogV1::model::NotebookMetadata> = None;
126                let mut modified: Option<chrono::DateTime<chrono::Utc>> = None;
127                let mut name: Option<String> = None;
128                let mut status: Option<crate::datadogV1::model::NotebookStatus> = None;
129                let mut time: Option<crate::datadogV1::model::NotebookGlobalTime> = None;
130                let mut additional_properties: std::collections::BTreeMap<
131                    String,
132                    serde_json::Value,
133                > = std::collections::BTreeMap::new();
134                let mut _unparsed = false;
135
136                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
137                    match k.as_str() {
138                        "author" => {
139                            if v.is_null() {
140                                continue;
141                            }
142                            author = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
143                        }
144                        "cells" => {
145                            if v.is_null() {
146                                continue;
147                            }
148                            cells = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
149                        }
150                        "created" => {
151                            if v.is_null() {
152                                continue;
153                            }
154                            created = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
155                        }
156                        "metadata" => {
157                            if v.is_null() {
158                                continue;
159                            }
160                            metadata = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
161                        }
162                        "modified" => {
163                            if v.is_null() {
164                                continue;
165                            }
166                            modified = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
167                        }
168                        "name" => {
169                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
170                        }
171                        "status" => {
172                            if v.is_null() {
173                                continue;
174                            }
175                            status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
176                            if let Some(ref _status) = status {
177                                match _status {
178                                    crate::datadogV1::model::NotebookStatus::UnparsedObject(
179                                        _status,
180                                    ) => {
181                                        _unparsed = true;
182                                    }
183                                    _ => {}
184                                }
185                            }
186                        }
187                        "time" => {
188                            if v.is_null() {
189                                continue;
190                            }
191                            time = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
192                            if let Some(ref _time) = time {
193                                match _time {
194                                    crate::datadogV1::model::NotebookGlobalTime::UnparsedObject(
195                                        _time,
196                                    ) => {
197                                        _unparsed = true;
198                                    }
199                                    _ => {}
200                                }
201                            }
202                        }
203                        &_ => {
204                            if let Ok(value) = serde_json::from_value(v.clone()) {
205                                additional_properties.insert(k, value);
206                            }
207                        }
208                    }
209                }
210                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
211
212                let content = NotebooksResponseDataAttributes {
213                    author,
214                    cells,
215                    created,
216                    metadata,
217                    modified,
218                    name,
219                    status,
220                    time,
221                    additional_properties,
222                    _unparsed,
223                };
224
225                Ok(content)
226            }
227        }
228
229        deserializer.deserialize_any(NotebooksResponseDataAttributesVisitor)
230    }
231}