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