datadog_api_client/datadogV2/model/
model_api_key_response.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 APIKeyResponse {
14 #[serde(rename = "data")]
16 pub data: Option<crate::datadogV2::model::FullAPIKey>,
17 #[serde(rename = "included")]
19 pub included: Option<Vec<crate::datadogV2::model::APIKeyResponseIncludedItem>>,
20 #[serde(flatten)]
21 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22 #[serde(skip)]
23 #[serde(default)]
24 pub(crate) _unparsed: bool,
25}
26
27impl APIKeyResponse {
28 pub fn new() -> APIKeyResponse {
29 APIKeyResponse {
30 data: None,
31 included: None,
32 additional_properties: std::collections::BTreeMap::new(),
33 _unparsed: false,
34 }
35 }
36
37 pub fn data(mut self, value: crate::datadogV2::model::FullAPIKey) -> Self {
38 self.data = Some(value);
39 self
40 }
41
42 pub fn included(
43 mut self,
44 value: Vec<crate::datadogV2::model::APIKeyResponseIncludedItem>,
45 ) -> Self {
46 self.included = Some(value);
47 self
48 }
49
50 pub fn additional_properties(
51 mut self,
52 value: std::collections::BTreeMap<String, serde_json::Value>,
53 ) -> Self {
54 self.additional_properties = value;
55 self
56 }
57}
58
59impl Default for APIKeyResponse {
60 fn default() -> Self {
61 Self::new()
62 }
63}
64
65impl<'de> Deserialize<'de> for APIKeyResponse {
66 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67 where
68 D: Deserializer<'de>,
69 {
70 struct APIKeyResponseVisitor;
71 impl<'a> Visitor<'a> for APIKeyResponseVisitor {
72 type Value = APIKeyResponse;
73
74 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
75 f.write_str("a mapping")
76 }
77
78 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
79 where
80 M: MapAccess<'a>,
81 {
82 let mut data: Option<crate::datadogV2::model::FullAPIKey> = None;
83 let mut included: Option<Vec<crate::datadogV2::model::APIKeyResponseIncludedItem>> =
84 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 "data" => {
94 if v.is_null() {
95 continue;
96 }
97 data = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
98 }
99 "included" => {
100 if v.is_null() {
101 continue;
102 }
103 included = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
104 }
105 &_ => {
106 if let Ok(value) = serde_json::from_value(v.clone()) {
107 additional_properties.insert(k, value);
108 }
109 }
110 }
111 }
112
113 let content = APIKeyResponse {
114 data,
115 included,
116 additional_properties,
117 _unparsed,
118 };
119
120 Ok(content)
121 }
122 }
123
124 deserializer.deserialize_any(APIKeyResponseVisitor)
125 }
126}