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