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