datadog_api_client/datadogV2/model/
model_entity_v3_api_datadog.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// Datadog product integrations for the API entity.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct EntityV3APIDatadog {
14    /// Schema for mapping source code locations to an entity.
15    #[serde(rename = "codeLocations")]
16    pub code_locations: Option<Vec<crate::datadogV2::model::EntityV3DatadogCodeLocationItem>>,
17    /// Events associations.
18    #[serde(rename = "events")]
19    pub events: Option<Vec<crate::datadogV2::model::EntityV3DatadogEventItem>>,
20    /// Logs association.
21    #[serde(rename = "logs")]
22    pub logs: Option<Vec<crate::datadogV2::model::EntityV3DatadogLogItem>>,
23    /// Performance stats association.
24    #[serde(rename = "performanceData")]
25    pub performance_data: Option<crate::datadogV2::model::EntityV3DatadogPerformance>,
26    /// CI Pipelines association.
27    #[serde(rename = "pipelines")]
28    pub pipelines: Option<crate::datadogV2::model::EntityV3DatadogPipelines>,
29    #[serde(skip)]
30    #[serde(default)]
31    pub(crate) _unparsed: bool,
32}
33
34impl EntityV3APIDatadog {
35    pub fn new() -> EntityV3APIDatadog {
36        EntityV3APIDatadog {
37            code_locations: None,
38            events: None,
39            logs: None,
40            performance_data: None,
41            pipelines: None,
42            _unparsed: false,
43        }
44    }
45
46    pub fn code_locations(
47        mut self,
48        value: Vec<crate::datadogV2::model::EntityV3DatadogCodeLocationItem>,
49    ) -> Self {
50        self.code_locations = Some(value);
51        self
52    }
53
54    pub fn events(mut self, value: Vec<crate::datadogV2::model::EntityV3DatadogEventItem>) -> Self {
55        self.events = Some(value);
56        self
57    }
58
59    pub fn logs(mut self, value: Vec<crate::datadogV2::model::EntityV3DatadogLogItem>) -> Self {
60        self.logs = Some(value);
61        self
62    }
63
64    pub fn performance_data(
65        mut self,
66        value: crate::datadogV2::model::EntityV3DatadogPerformance,
67    ) -> Self {
68        self.performance_data = Some(value);
69        self
70    }
71
72    pub fn pipelines(mut self, value: crate::datadogV2::model::EntityV3DatadogPipelines) -> Self {
73        self.pipelines = Some(value);
74        self
75    }
76}
77
78impl Default for EntityV3APIDatadog {
79    fn default() -> Self {
80        Self::new()
81    }
82}
83
84impl<'de> Deserialize<'de> for EntityV3APIDatadog {
85    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
86    where
87        D: Deserializer<'de>,
88    {
89        struct EntityV3APIDatadogVisitor;
90        impl<'a> Visitor<'a> for EntityV3APIDatadogVisitor {
91            type Value = EntityV3APIDatadog;
92
93            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
94                f.write_str("a mapping")
95            }
96
97            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
98            where
99                M: MapAccess<'a>,
100            {
101                let mut code_locations: Option<
102                    Vec<crate::datadogV2::model::EntityV3DatadogCodeLocationItem>,
103                > = None;
104                let mut events: Option<Vec<crate::datadogV2::model::EntityV3DatadogEventItem>> =
105                    None;
106                let mut logs: Option<Vec<crate::datadogV2::model::EntityV3DatadogLogItem>> = None;
107                let mut performance_data: Option<
108                    crate::datadogV2::model::EntityV3DatadogPerformance,
109                > = None;
110                let mut pipelines: Option<crate::datadogV2::model::EntityV3DatadogPipelines> = None;
111                let mut _unparsed = false;
112
113                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
114                    match k.as_str() {
115                        "codeLocations" => {
116                            if v.is_null() {
117                                continue;
118                            }
119                            code_locations =
120                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
121                        }
122                        "events" => {
123                            if v.is_null() {
124                                continue;
125                            }
126                            events = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
127                        }
128                        "logs" => {
129                            if v.is_null() {
130                                continue;
131                            }
132                            logs = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
133                        }
134                        "performanceData" => {
135                            if v.is_null() {
136                                continue;
137                            }
138                            performance_data =
139                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
140                        }
141                        "pipelines" => {
142                            if v.is_null() {
143                                continue;
144                            }
145                            pipelines = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
146                        }
147                        &_ => {
148                            return Err(serde::de::Error::custom(
149                                "Additional properties not allowed",
150                            ));
151                        }
152                    }
153                }
154
155                let content = EntityV3APIDatadog {
156                    code_locations,
157                    events,
158                    logs,
159                    performance_data,
160                    pipelines,
161                    _unparsed,
162                };
163
164                Ok(content)
165            }
166        }
167
168        deserializer.deserialize_any(EntityV3APIDatadogVisitor)
169    }
170}