datadog_api_client/datadogV1/model/
model_notebook_update_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 data attributes of a notebook.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct NotebookUpdateDataAttributes {
14    /// List of cells to display in the notebook.
15    #[serde(rename = "cells")]
16    pub cells: Vec<crate::datadogV1::model::NotebookUpdateCell>,
17    /// Metadata associated with the notebook.
18    #[serde(rename = "metadata")]
19    pub metadata: Option<crate::datadogV1::model::NotebookMetadata>,
20    /// The name of the notebook.
21    #[serde(rename = "name")]
22    pub name: String,
23    /// Publication status of the notebook. For now, always "published".
24    #[serde(rename = "status")]
25    pub status: Option<crate::datadogV1::model::NotebookStatus>,
26    /// Notebook global timeframe.
27    #[serde(rename = "time")]
28    pub time: crate::datadogV1::model::NotebookGlobalTime,
29    #[serde(flatten)]
30    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
31    #[serde(skip)]
32    #[serde(default)]
33    pub(crate) _unparsed: bool,
34}
35
36impl NotebookUpdateDataAttributes {
37    pub fn new(
38        cells: Vec<crate::datadogV1::model::NotebookUpdateCell>,
39        name: String,
40        time: crate::datadogV1::model::NotebookGlobalTime,
41    ) -> NotebookUpdateDataAttributes {
42        NotebookUpdateDataAttributes {
43            cells,
44            metadata: None,
45            name,
46            status: None,
47            time,
48            additional_properties: std::collections::BTreeMap::new(),
49            _unparsed: false,
50        }
51    }
52
53    pub fn metadata(mut self, value: crate::datadogV1::model::NotebookMetadata) -> Self {
54        self.metadata = Some(value);
55        self
56    }
57
58    pub fn status(mut self, value: crate::datadogV1::model::NotebookStatus) -> Self {
59        self.status = Some(value);
60        self
61    }
62
63    pub fn additional_properties(
64        mut self,
65        value: std::collections::BTreeMap<String, serde_json::Value>,
66    ) -> Self {
67        self.additional_properties = value;
68        self
69    }
70}
71
72impl<'de> Deserialize<'de> for NotebookUpdateDataAttributes {
73    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
74    where
75        D: Deserializer<'de>,
76    {
77        struct NotebookUpdateDataAttributesVisitor;
78        impl<'a> Visitor<'a> for NotebookUpdateDataAttributesVisitor {
79            type Value = NotebookUpdateDataAttributes;
80
81            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
82                f.write_str("a mapping")
83            }
84
85            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
86            where
87                M: MapAccess<'a>,
88            {
89                let mut cells: Option<Vec<crate::datadogV1::model::NotebookUpdateCell>> = None;
90                let mut metadata: Option<crate::datadogV1::model::NotebookMetadata> = None;
91                let mut name: Option<String> = None;
92                let mut status: Option<crate::datadogV1::model::NotebookStatus> = None;
93                let mut time: Option<crate::datadogV1::model::NotebookGlobalTime> = None;
94                let mut additional_properties: std::collections::BTreeMap<
95                    String,
96                    serde_json::Value,
97                > = std::collections::BTreeMap::new();
98                let mut _unparsed = false;
99
100                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
101                    match k.as_str() {
102                        "cells" => {
103                            cells = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
104                        }
105                        "metadata" => {
106                            if v.is_null() {
107                                continue;
108                            }
109                            metadata = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
110                        }
111                        "name" => {
112                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
113                        }
114                        "status" => {
115                            if v.is_null() {
116                                continue;
117                            }
118                            status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
119                            if let Some(ref _status) = status {
120                                match _status {
121                                    crate::datadogV1::model::NotebookStatus::UnparsedObject(
122                                        _status,
123                                    ) => {
124                                        _unparsed = true;
125                                    }
126                                    _ => {}
127                                }
128                            }
129                        }
130                        "time" => {
131                            time = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
132                            if let Some(ref _time) = time {
133                                match _time {
134                                    crate::datadogV1::model::NotebookGlobalTime::UnparsedObject(
135                                        _time,
136                                    ) => {
137                                        _unparsed = true;
138                                    }
139                                    _ => {}
140                                }
141                            }
142                        }
143                        &_ => {
144                            if let Ok(value) = serde_json::from_value(v.clone()) {
145                                additional_properties.insert(k, value);
146                            }
147                        }
148                    }
149                }
150                let cells = cells.ok_or_else(|| M::Error::missing_field("cells"))?;
151                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
152                let time = time.ok_or_else(|| M::Error::missing_field("time"))?;
153
154                let content = NotebookUpdateDataAttributes {
155                    cells,
156                    metadata,
157                    name,
158                    status,
159                    time,
160                    additional_properties,
161                    _unparsed,
162                };
163
164                Ok(content)
165            }
166        }
167
168        deserializer.deserialize_any(NotebookUpdateDataAttributesVisitor)
169    }
170}