datadog_api_client/datadogV2/model/
model_notion_integration_update.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct NotionIntegrationUpdate {
14 #[serde(rename = "credentials")]
16 pub credentials: Option<crate::datadogV2::model::NotionCredentialsUpdate>,
17 #[serde(rename = "type")]
19 pub type_: crate::datadogV2::model::NotionIntegrationType,
20 #[serde(flatten)]
21 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22 #[serde(skip)]
23 #[serde(default)]
24 pub(crate) _unparsed: bool,
25}
26
27impl NotionIntegrationUpdate {
28 pub fn new(type_: crate::datadogV2::model::NotionIntegrationType) -> NotionIntegrationUpdate {
29 NotionIntegrationUpdate {
30 credentials: None,
31 type_,
32 additional_properties: std::collections::BTreeMap::new(),
33 _unparsed: false,
34 }
35 }
36
37 pub fn credentials(mut self, value: crate::datadogV2::model::NotionCredentialsUpdate) -> Self {
38 self.credentials = Some(value);
39 self
40 }
41
42 pub fn additional_properties(
43 mut self,
44 value: std::collections::BTreeMap<String, serde_json::Value>,
45 ) -> Self {
46 self.additional_properties = value;
47 self
48 }
49}
50
51impl<'de> Deserialize<'de> for NotionIntegrationUpdate {
52 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
53 where
54 D: Deserializer<'de>,
55 {
56 struct NotionIntegrationUpdateVisitor;
57 impl<'a> Visitor<'a> for NotionIntegrationUpdateVisitor {
58 type Value = NotionIntegrationUpdate;
59
60 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
61 f.write_str("a mapping")
62 }
63
64 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
65 where
66 M: MapAccess<'a>,
67 {
68 let mut credentials: Option<crate::datadogV2::model::NotionCredentialsUpdate> =
69 None;
70 let mut type_: Option<crate::datadogV2::model::NotionIntegrationType> = None;
71 let mut additional_properties: std::collections::BTreeMap<
72 String,
73 serde_json::Value,
74 > = std::collections::BTreeMap::new();
75 let mut _unparsed = false;
76
77 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
78 match k.as_str() {
79 "credentials" => {
80 if v.is_null() {
81 continue;
82 }
83 credentials =
84 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
85 if let Some(ref _credentials) = credentials {
86 match _credentials {
87 crate::datadogV2::model::NotionCredentialsUpdate::UnparsedObject(_credentials) => {
88 _unparsed = true;
89 },
90 _ => {}
91 }
92 }
93 }
94 "type" => {
95 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
96 if let Some(ref _type_) = type_ {
97 match _type_ {
98 crate::datadogV2::model::NotionIntegrationType::UnparsedObject(_type_) => {
99 _unparsed = true;
100 },
101 _ => {}
102 }
103 }
104 }
105 &_ => {
106 if let Ok(value) = serde_json::from_value(v.clone()) {
107 additional_properties.insert(k, value);
108 }
109 }
110 }
111 }
112 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
113
114 let content = NotionIntegrationUpdate {
115 credentials,
116 type_,
117 additional_properties,
118 _unparsed,
119 };
120
121 Ok(content)
122 }
123 }
124
125 deserializer.deserialize_any(NotionIntegrationUpdateVisitor)
126 }
127}