datadog_api_client/datadogV2/model/
model_entity_v3_system_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 EntityV3SystemSpec {
14    #[serde(rename = "components")]
16    pub components: Option<Vec<String>>,
17    #[serde(rename = "lifecycle")]
19    pub lifecycle: Option<String>,
20    #[serde(rename = "tier")]
22    pub tier: Option<String>,
23    #[serde(skip)]
24    #[serde(default)]
25    pub(crate) _unparsed: bool,
26}
27
28impl EntityV3SystemSpec {
29    pub fn new() -> EntityV3SystemSpec {
30        EntityV3SystemSpec {
31            components: None,
32            lifecycle: None,
33            tier: None,
34            _unparsed: false,
35        }
36    }
37
38    pub fn components(mut self, value: Vec<String>) -> Self {
39        self.components = Some(value);
40        self
41    }
42
43    pub fn lifecycle(mut self, value: String) -> Self {
44        self.lifecycle = Some(value);
45        self
46    }
47
48    pub fn tier(mut self, value: String) -> Self {
49        self.tier = Some(value);
50        self
51    }
52}
53
54impl Default for EntityV3SystemSpec {
55    fn default() -> Self {
56        Self::new()
57    }
58}
59
60impl<'de> Deserialize<'de> for EntityV3SystemSpec {
61    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
62    where
63        D: Deserializer<'de>,
64    {
65        struct EntityV3SystemSpecVisitor;
66        impl<'a> Visitor<'a> for EntityV3SystemSpecVisitor {
67            type Value = EntityV3SystemSpec;
68
69            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
70                f.write_str("a mapping")
71            }
72
73            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
74            where
75                M: MapAccess<'a>,
76            {
77                let mut components: Option<Vec<String>> = None;
78                let mut lifecycle: Option<String> = None;
79                let mut tier: Option<String> = None;
80                let mut _unparsed = false;
81
82                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
83                    match k.as_str() {
84                        "components" => {
85                            if v.is_null() {
86                                continue;
87                            }
88                            components = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
89                        }
90                        "lifecycle" => {
91                            if v.is_null() {
92                                continue;
93                            }
94                            lifecycle = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
95                        }
96                        "tier" => {
97                            if v.is_null() {
98                                continue;
99                            }
100                            tier = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
101                        }
102                        &_ => {
103                            return Err(serde::de::Error::custom(
104                                "Additional properties not allowed",
105                            ));
106                        }
107                    }
108                }
109
110                let content = EntityV3SystemSpec {
111                    components,
112                    lifecycle,
113                    tier,
114                    _unparsed,
115                };
116
117                Ok(content)
118            }
119        }
120
121        deserializer.deserialize_any(EntityV3SystemSpecVisitor)
122    }
123}