datadog_api_client/datadogV1/model/
model_notebook_create_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 NotebookCreateDataAttributes {
14    /// List of cells to display in the notebook.
15    #[serde(rename = "cells")]
16    pub cells: Vec<crate::datadogV1::model::NotebookCellCreateRequest>,
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 NotebookCreateDataAttributes {
37    pub fn new(
38        cells: Vec<crate::datadogV1::model::NotebookCellCreateRequest>,
39        name: String,
40        time: crate::datadogV1::model::NotebookGlobalTime,
41    ) -> NotebookCreateDataAttributes {
42        NotebookCreateDataAttributes {
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 NotebookCreateDataAttributes {
73    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
74    where
75        D: Deserializer<'de>,
76    {
77        struct NotebookCreateDataAttributesVisitor;
78        impl<'a> Visitor<'a> for NotebookCreateDataAttributesVisitor {
79            type Value = NotebookCreateDataAttributes;
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::NotebookCellCreateRequest>> =
90                    None;
91                let mut metadata: Option<crate::datadogV1::model::NotebookMetadata> = None;
92                let mut name: Option<String> = None;
93                let mut status: Option<crate::datadogV1::model::NotebookStatus> = None;
94                let mut time: Option<crate::datadogV1::model::NotebookGlobalTime> = None;
95                let mut additional_properties: std::collections::BTreeMap<
96                    String,
97                    serde_json::Value,
98                > = std::collections::BTreeMap::new();
99                let mut _unparsed = false;
100
101                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
102                    match k.as_str() {
103                        "cells" => {
104                            cells = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
105                        }
106                        "metadata" => {
107                            if v.is_null() {
108                                continue;
109                            }
110                            metadata = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
111                        }
112                        "name" => {
113                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114                        }
115                        "status" => {
116                            if v.is_null() {
117                                continue;
118                            }
119                            status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
120                            if let Some(ref _status) = status {
121                                match _status {
122                                    crate::datadogV1::model::NotebookStatus::UnparsedObject(
123                                        _status,
124                                    ) => {
125                                        _unparsed = true;
126                                    }
127                                    _ => {}
128                                }
129                            }
130                        }
131                        "time" => {
132                            time = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
133                            if let Some(ref _time) = time {
134                                match _time {
135                                    crate::datadogV1::model::NotebookGlobalTime::UnparsedObject(
136                                        _time,
137                                    ) => {
138                                        _unparsed = true;
139                                    }
140                                    _ => {}
141                                }
142                            }
143                        }
144                        &_ => {
145                            if let Ok(value) = serde_json::from_value(v.clone()) {
146                                additional_properties.insert(k, value);
147                            }
148                        }
149                    }
150                }
151                let cells = cells.ok_or_else(|| M::Error::missing_field("cells"))?;
152                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
153                let time = time.ok_or_else(|| M::Error::missing_field("time"))?;
154
155                let content = NotebookCreateDataAttributes {
156                    cells,
157                    metadata,
158                    name,
159                    status,
160                    time,
161                    additional_properties,
162                    _unparsed,
163                };
164
165                Ok(content)
166            }
167        }
168
169        deserializer.deserialize_any(NotebookCreateDataAttributesVisitor)
170    }
171}