datadog_api_client/datadogV1/model/
model_notebook_cell_update_request.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 description of a notebook cell update request.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct NotebookCellUpdateRequest {
14    /// The attributes of a notebook cell in update cell request. Valid cell types are `markdown`, `timeseries`, `toplist`, `heatmap`, `distribution`,
15    /// `log_stream`. [More information on each graph visualization type.](<https://docs.datadoghq.com/dashboards/widgets/>)
16    #[serde(rename = "attributes")]
17    pub attributes: crate::datadogV1::model::NotebookCellUpdateRequestAttributes,
18    /// Notebook cell ID.
19    #[serde(rename = "id")]
20    pub id: String,
21    /// Type of the Notebook Cell resource.
22    #[serde(rename = "type")]
23    pub type_: crate::datadogV1::model::NotebookCellResourceType,
24    #[serde(flatten)]
25    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
26    #[serde(skip)]
27    #[serde(default)]
28    pub(crate) _unparsed: bool,
29}
30
31impl NotebookCellUpdateRequest {
32    pub fn new(
33        attributes: crate::datadogV1::model::NotebookCellUpdateRequestAttributes,
34        id: String,
35        type_: crate::datadogV1::model::NotebookCellResourceType,
36    ) -> NotebookCellUpdateRequest {
37        NotebookCellUpdateRequest {
38            attributes,
39            id,
40            type_,
41            additional_properties: std::collections::BTreeMap::new(),
42            _unparsed: false,
43        }
44    }
45
46    pub fn additional_properties(
47        mut self,
48        value: std::collections::BTreeMap<String, serde_json::Value>,
49    ) -> Self {
50        self.additional_properties = value;
51        self
52    }
53}
54
55impl<'de> Deserialize<'de> for NotebookCellUpdateRequest {
56    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
57    where
58        D: Deserializer<'de>,
59    {
60        struct NotebookCellUpdateRequestVisitor;
61        impl<'a> Visitor<'a> for NotebookCellUpdateRequestVisitor {
62            type Value = NotebookCellUpdateRequest;
63
64            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
65                f.write_str("a mapping")
66            }
67
68            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
69            where
70                M: MapAccess<'a>,
71            {
72                let mut attributes: Option<
73                    crate::datadogV1::model::NotebookCellUpdateRequestAttributes,
74                > = None;
75                let mut id: Option<String> = None;
76                let mut type_: Option<crate::datadogV1::model::NotebookCellResourceType> = None;
77                let mut additional_properties: std::collections::BTreeMap<
78                    String,
79                    serde_json::Value,
80                > = std::collections::BTreeMap::new();
81                let mut _unparsed = false;
82
83                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
84                    match k.as_str() {
85                        "attributes" => {
86                            attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
87                            if let Some(ref _attributes) = attributes {
88                                match _attributes {
89                                    crate::datadogV1::model::NotebookCellUpdateRequestAttributes::UnparsedObject(_attributes) => {
90                                        _unparsed = true;
91                                    },
92                                    _ => {}
93                                }
94                            }
95                        }
96                        "id" => {
97                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
98                        }
99                        "type" => {
100                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
101                            if let Some(ref _type_) = type_ {
102                                match _type_ {
103                                    crate::datadogV1::model::NotebookCellResourceType::UnparsedObject(_type_) => {
104                                        _unparsed = true;
105                                    },
106                                    _ => {}
107                                }
108                            }
109                        }
110                        &_ => {
111                            if let Ok(value) = serde_json::from_value(v.clone()) {
112                                additional_properties.insert(k, value);
113                            }
114                        }
115                    }
116                }
117                let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?;
118                let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
119                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
120
121                let content = NotebookCellUpdateRequest {
122                    attributes,
123                    id,
124                    type_,
125                    additional_properties,
126                    _unparsed,
127                };
128
129                Ok(content)
130            }
131        }
132
133        deserializer.deserialize_any(NotebookCellUpdateRequestVisitor)
134    }
135}