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