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