datadog_api_client/datadogV2/model/
model_entity_v3_api.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 EntityV3API {
14 #[serde(rename = "apiVersion")]
16 pub api_version: crate::datadogV2::model::EntityV3APIVersion,
17 #[serde(rename = "datadog")]
19 pub datadog: Option<crate::datadogV2::model::EntityV3APIDatadog>,
20 #[serde(rename = "extensions")]
22 pub extensions: Option<std::collections::BTreeMap<String, serde_json::Value>>,
23 #[serde(rename = "integrations")]
25 pub integrations: Option<crate::datadogV2::model::EntityV3Integrations>,
26 #[serde(rename = "kind")]
28 pub kind: crate::datadogV2::model::EntityV3APIKind,
29 #[serde(rename = "metadata")]
31 pub metadata: crate::datadogV2::model::EntityV3Metadata,
32 #[serde(rename = "spec")]
34 pub spec: Option<crate::datadogV2::model::EntityV3APISpec>,
35 #[serde(skip)]
36 #[serde(default)]
37 pub(crate) _unparsed: bool,
38}
39
40impl EntityV3API {
41 pub fn new(
42 api_version: crate::datadogV2::model::EntityV3APIVersion,
43 kind: crate::datadogV2::model::EntityV3APIKind,
44 metadata: crate::datadogV2::model::EntityV3Metadata,
45 ) -> EntityV3API {
46 EntityV3API {
47 api_version,
48 datadog: None,
49 extensions: None,
50 integrations: None,
51 kind,
52 metadata,
53 spec: None,
54 _unparsed: false,
55 }
56 }
57
58 pub fn datadog(mut self, value: crate::datadogV2::model::EntityV3APIDatadog) -> Self {
59 self.datadog = Some(value);
60 self
61 }
62
63 pub fn extensions(
64 mut self,
65 value: std::collections::BTreeMap<String, serde_json::Value>,
66 ) -> Self {
67 self.extensions = Some(value);
68 self
69 }
70
71 pub fn integrations(mut self, value: crate::datadogV2::model::EntityV3Integrations) -> Self {
72 self.integrations = Some(value);
73 self
74 }
75
76 pub fn spec(mut self, value: crate::datadogV2::model::EntityV3APISpec) -> Self {
77 self.spec = Some(value);
78 self
79 }
80}
81
82impl<'de> Deserialize<'de> for EntityV3API {
83 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
84 where
85 D: Deserializer<'de>,
86 {
87 struct EntityV3APIVisitor;
88 impl<'a> Visitor<'a> for EntityV3APIVisitor {
89 type Value = EntityV3API;
90
91 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
92 f.write_str("a mapping")
93 }
94
95 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
96 where
97 M: MapAccess<'a>,
98 {
99 let mut api_version: Option<crate::datadogV2::model::EntityV3APIVersion> = None;
100 let mut datadog: Option<crate::datadogV2::model::EntityV3APIDatadog> = None;
101 let mut extensions: Option<std::collections::BTreeMap<String, serde_json::Value>> =
102 None;
103 let mut integrations: Option<crate::datadogV2::model::EntityV3Integrations> = None;
104 let mut kind: Option<crate::datadogV2::model::EntityV3APIKind> = None;
105 let mut metadata: Option<crate::datadogV2::model::EntityV3Metadata> = None;
106 let mut spec: Option<crate::datadogV2::model::EntityV3APISpec> = None;
107 let mut _unparsed = false;
108
109 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
110 match k.as_str() {
111 "apiVersion" => {
112 api_version =
113 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114 if let Some(ref _api_version) = api_version {
115 match _api_version {
116 crate::datadogV2::model::EntityV3APIVersion::UnparsedObject(
117 _api_version,
118 ) => {
119 _unparsed = true;
120 }
121 _ => {}
122 }
123 }
124 }
125 "datadog" => {
126 if v.is_null() {
127 continue;
128 }
129 datadog = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
130 }
131 "extensions" => {
132 if v.is_null() {
133 continue;
134 }
135 extensions = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
136 }
137 "integrations" => {
138 if v.is_null() {
139 continue;
140 }
141 integrations =
142 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
143 }
144 "kind" => {
145 kind = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
146 if let Some(ref _kind) = kind {
147 match _kind {
148 crate::datadogV2::model::EntityV3APIKind::UnparsedObject(
149 _kind,
150 ) => {
151 _unparsed = true;
152 }
153 _ => {}
154 }
155 }
156 }
157 "metadata" => {
158 metadata = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
159 }
160 "spec" => {
161 if v.is_null() {
162 continue;
163 }
164 spec = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
165 }
166 &_ => {
167 return Err(serde::de::Error::custom(
168 "Additional properties not allowed",
169 ));
170 }
171 }
172 }
173 let api_version =
174 api_version.ok_or_else(|| M::Error::missing_field("api_version"))?;
175 let kind = kind.ok_or_else(|| M::Error::missing_field("kind"))?;
176 let metadata = metadata.ok_or_else(|| M::Error::missing_field("metadata"))?;
177
178 let content = EntityV3API {
179 api_version,
180 datadog,
181 extensions,
182 integrations,
183 kind,
184 metadata,
185 spec,
186 _unparsed,
187 };
188
189 Ok(content)
190 }
191 }
192
193 deserializer.deserialize_any(EntityV3APIVisitor)
194 }
195}