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