datadog_api_client/datadogV2/model/
model_entity_attributes.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 EntityAttributes {
14 #[serde(rename = "apiVersion")]
16 pub api_version: Option<String>,
17 #[serde(rename = "description")]
19 pub description: Option<String>,
20 #[serde(rename = "displayName")]
22 pub display_name: Option<String>,
23 #[serde(rename = "kind")]
25 pub kind: Option<String>,
26 #[serde(rename = "name")]
28 pub name: Option<String>,
29 #[serde(rename = "namespace")]
31 pub namespace: Option<String>,
32 #[serde(rename = "owner")]
34 pub owner: Option<String>,
35 #[serde(rename = "tags")]
37 pub tags: Option<Vec<String>>,
38 #[serde(flatten)]
39 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
40 #[serde(skip)]
41 #[serde(default)]
42 pub(crate) _unparsed: bool,
43}
44
45impl EntityAttributes {
46 pub fn new() -> EntityAttributes {
47 EntityAttributes {
48 api_version: None,
49 description: None,
50 display_name: None,
51 kind: None,
52 name: None,
53 namespace: None,
54 owner: None,
55 tags: None,
56 additional_properties: std::collections::BTreeMap::new(),
57 _unparsed: false,
58 }
59 }
60
61 pub fn api_version(mut self, value: String) -> Self {
62 self.api_version = Some(value);
63 self
64 }
65
66 pub fn description(mut self, value: String) -> Self {
67 self.description = Some(value);
68 self
69 }
70
71 pub fn display_name(mut self, value: String) -> Self {
72 self.display_name = Some(value);
73 self
74 }
75
76 pub fn kind(mut self, value: String) -> Self {
77 self.kind = Some(value);
78 self
79 }
80
81 pub fn name(mut self, value: String) -> Self {
82 self.name = Some(value);
83 self
84 }
85
86 pub fn namespace(mut self, value: String) -> Self {
87 self.namespace = Some(value);
88 self
89 }
90
91 pub fn owner(mut self, value: String) -> Self {
92 self.owner = Some(value);
93 self
94 }
95
96 pub fn tags(mut self, value: Vec<String>) -> Self {
97 self.tags = Some(value);
98 self
99 }
100
101 pub fn additional_properties(
102 mut self,
103 value: std::collections::BTreeMap<String, serde_json::Value>,
104 ) -> Self {
105 self.additional_properties = value;
106 self
107 }
108}
109
110impl Default for EntityAttributes {
111 fn default() -> Self {
112 Self::new()
113 }
114}
115
116impl<'de> Deserialize<'de> for EntityAttributes {
117 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
118 where
119 D: Deserializer<'de>,
120 {
121 struct EntityAttributesVisitor;
122 impl<'a> Visitor<'a> for EntityAttributesVisitor {
123 type Value = EntityAttributes;
124
125 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
126 f.write_str("a mapping")
127 }
128
129 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
130 where
131 M: MapAccess<'a>,
132 {
133 let mut api_version: Option<String> = None;
134 let mut description: Option<String> = None;
135 let mut display_name: Option<String> = None;
136 let mut kind: Option<String> = None;
137 let mut name: Option<String> = None;
138 let mut namespace: Option<String> = None;
139 let mut owner: Option<String> = None;
140 let mut tags: Option<Vec<String>> = None;
141 let mut additional_properties: std::collections::BTreeMap<
142 String,
143 serde_json::Value,
144 > = std::collections::BTreeMap::new();
145 let mut _unparsed = false;
146
147 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
148 match k.as_str() {
149 "apiVersion" => {
150 if v.is_null() {
151 continue;
152 }
153 api_version =
154 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
155 }
156 "description" => {
157 if v.is_null() {
158 continue;
159 }
160 description =
161 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
162 }
163 "displayName" => {
164 if v.is_null() {
165 continue;
166 }
167 display_name =
168 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
169 }
170 "kind" => {
171 if v.is_null() {
172 continue;
173 }
174 kind = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
175 }
176 "name" => {
177 if v.is_null() {
178 continue;
179 }
180 name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
181 }
182 "namespace" => {
183 if v.is_null() {
184 continue;
185 }
186 namespace = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
187 }
188 "owner" => {
189 if v.is_null() {
190 continue;
191 }
192 owner = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
193 }
194 "tags" => {
195 if v.is_null() {
196 continue;
197 }
198 tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
199 }
200 &_ => {
201 if let Ok(value) = serde_json::from_value(v.clone()) {
202 additional_properties.insert(k, value);
203 }
204 }
205 }
206 }
207
208 let content = EntityAttributes {
209 api_version,
210 description,
211 display_name,
212 kind,
213 name,
214 namespace,
215 owner,
216 tags,
217 additional_properties,
218 _unparsed,
219 };
220
221 Ok(content)
222 }
223 }
224
225 deserializer.deserialize_any(EntityAttributesVisitor)
226 }
227}