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