datadog_api_client/datadogV2/model/
model_entity_v3_datastore.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 EntityV3Datastore {
14 #[serde(rename = "apiVersion")]
16 pub api_version: crate::datadogV2::model::EntityV3APIVersion,
17 #[serde(rename = "datadog")]
19 pub datadog: Option<crate::datadogV2::model::EntityV3DatastoreDatadog>,
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::EntityV3DatastoreKind,
29 #[serde(rename = "metadata")]
31 pub metadata: crate::datadogV2::model::EntityV3Metadata,
32 #[serde(rename = "spec")]
34 pub spec: Option<crate::datadogV2::model::EntityV3DatastoreSpec>,
35 #[serde(skip)]
36 #[serde(default)]
37 pub(crate) _unparsed: bool,
38}
39
40impl EntityV3Datastore {
41 pub fn new(
42 api_version: crate::datadogV2::model::EntityV3APIVersion,
43 kind: crate::datadogV2::model::EntityV3DatastoreKind,
44 metadata: crate::datadogV2::model::EntityV3Metadata,
45 ) -> EntityV3Datastore {
46 EntityV3Datastore {
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::EntityV3DatastoreDatadog) -> 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::EntityV3DatastoreSpec) -> Self {
77 self.spec = Some(value);
78 self
79 }
80}
81
82impl<'de> Deserialize<'de> for EntityV3Datastore {
83 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
84 where
85 D: Deserializer<'de>,
86 {
87 struct EntityV3DatastoreVisitor;
88 impl<'a> Visitor<'a> for EntityV3DatastoreVisitor {
89 type Value = EntityV3Datastore;
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::EntityV3DatastoreDatadog> = 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::EntityV3DatastoreKind> = None;
105 let mut metadata: Option<crate::datadogV2::model::EntityV3Metadata> = None;
106 let mut spec: Option<crate::datadogV2::model::EntityV3DatastoreSpec> = 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::EntityV3DatastoreKind::UnparsedObject(_kind) => {
149 _unparsed = true;
150 },
151 _ => {}
152 }
153 }
154 }
155 "metadata" => {
156 metadata = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
157 }
158 "spec" => {
159 if v.is_null() {
160 continue;
161 }
162 spec = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
163 }
164 &_ => {
165 return Err(serde::de::Error::custom(
166 "Additional properties not allowed",
167 ));
168 }
169 }
170 }
171 let api_version =
172 api_version.ok_or_else(|| M::Error::missing_field("api_version"))?;
173 let kind = kind.ok_or_else(|| M::Error::missing_field("kind"))?;
174 let metadata = metadata.ok_or_else(|| M::Error::missing_field("metadata"))?;
175
176 let content = EntityV3Datastore {
177 api_version,
178 datadog,
179 extensions,
180 integrations,
181 kind,
182 metadata,
183 spec,
184 _unparsed,
185 };
186
187 Ok(content)
188 }
189 }
190
191 deserializer.deserialize_any(EntityV3DatastoreVisitor)
192 }
193}