datadog_api_client/datadogV2/model/
model_org_connection.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 OrgConnection {
14 #[serde(rename = "attributes")]
16 pub attributes: crate::datadogV2::model::OrgConnectionAttributes,
17 #[serde(rename = "id")]
19 pub id: uuid::Uuid,
20 #[serde(rename = "relationships")]
22 pub relationships: crate::datadogV2::model::OrgConnectionRelationships,
23 #[serde(rename = "type")]
25 pub type_: crate::datadogV2::model::OrgConnectionType,
26 #[serde(flatten)]
27 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
28 #[serde(skip)]
29 #[serde(default)]
30 pub(crate) _unparsed: bool,
31}
32
33impl OrgConnection {
34 pub fn new(
35 attributes: crate::datadogV2::model::OrgConnectionAttributes,
36 id: uuid::Uuid,
37 relationships: crate::datadogV2::model::OrgConnectionRelationships,
38 type_: crate::datadogV2::model::OrgConnectionType,
39 ) -> OrgConnection {
40 OrgConnection {
41 attributes,
42 id,
43 relationships,
44 type_,
45 additional_properties: std::collections::BTreeMap::new(),
46 _unparsed: false,
47 }
48 }
49
50 pub fn additional_properties(
51 mut self,
52 value: std::collections::BTreeMap<String, serde_json::Value>,
53 ) -> Self {
54 self.additional_properties = value;
55 self
56 }
57}
58
59impl<'de> Deserialize<'de> for OrgConnection {
60 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
61 where
62 D: Deserializer<'de>,
63 {
64 struct OrgConnectionVisitor;
65 impl<'a> Visitor<'a> for OrgConnectionVisitor {
66 type Value = OrgConnection;
67
68 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
69 f.write_str("a mapping")
70 }
71
72 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
73 where
74 M: MapAccess<'a>,
75 {
76 let mut attributes: Option<crate::datadogV2::model::OrgConnectionAttributes> = None;
77 let mut id: Option<uuid::Uuid> = None;
78 let mut relationships: Option<crate::datadogV2::model::OrgConnectionRelationships> =
79 None;
80 let mut type_: Option<crate::datadogV2::model::OrgConnectionType> = None;
81 let mut additional_properties: std::collections::BTreeMap<
82 String,
83 serde_json::Value,
84 > = std::collections::BTreeMap::new();
85 let mut _unparsed = false;
86
87 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
88 match k.as_str() {
89 "attributes" => {
90 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
91 }
92 "id" => {
93 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
94 }
95 "relationships" => {
96 relationships =
97 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::datadogV2::model::OrgConnectionType::UnparsedObject(
104 _type_,
105 ) => {
106 _unparsed = true;
107 }
108 _ => {}
109 }
110 }
111 }
112 &_ => {
113 if let Ok(value) = serde_json::from_value(v.clone()) {
114 additional_properties.insert(k, value);
115 }
116 }
117 }
118 }
119 let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?;
120 let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
121 let relationships =
122 relationships.ok_or_else(|| M::Error::missing_field("relationships"))?;
123 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
124
125 let content = OrgConnection {
126 attributes,
127 id,
128 relationships,
129 type_,
130 additional_properties,
131 _unparsed,
132 };
133
134 Ok(content)
135 }
136 }
137
138 deserializer.deserialize_any(OrgConnectionVisitor)
139 }
140}