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