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