datadog_api_client/datadogV2/model/
model_service_definition_meta.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/// Metadata about a service definition.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ServiceDefinitionMeta {
14    /// GitHub HTML URL.
15    #[serde(rename = "github-html-url")]
16    pub github_html_url: Option<String>,
17    /// Ingestion schema version.
18    #[serde(rename = "ingested-schema-version")]
19    pub ingested_schema_version: Option<String>,
20    /// Ingestion source of the service definition.
21    #[serde(rename = "ingestion-source")]
22    pub ingestion_source: Option<String>,
23    /// Last modified time of the service definition.
24    #[serde(rename = "last-modified-time")]
25    pub last_modified_time: Option<String>,
26    /// User defined origin of the service definition.
27    #[serde(rename = "origin")]
28    pub origin: Option<String>,
29    /// User defined origin's detail of the service definition.
30    #[serde(rename = "origin-detail")]
31    pub origin_detail: Option<String>,
32    /// A list of schema validation warnings.
33    #[serde(rename = "warnings")]
34    pub warnings: Option<Vec<crate::datadogV2::model::ServiceDefinitionMetaWarnings>>,
35    #[serde(flatten)]
36    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
37    #[serde(skip)]
38    #[serde(default)]
39    pub(crate) _unparsed: bool,
40}
41
42impl ServiceDefinitionMeta {
43    pub fn new() -> ServiceDefinitionMeta {
44        ServiceDefinitionMeta {
45            github_html_url: None,
46            ingested_schema_version: None,
47            ingestion_source: None,
48            last_modified_time: None,
49            origin: None,
50            origin_detail: None,
51            warnings: None,
52            additional_properties: std::collections::BTreeMap::new(),
53            _unparsed: false,
54        }
55    }
56
57    pub fn github_html_url(mut self, value: String) -> Self {
58        self.github_html_url = Some(value);
59        self
60    }
61
62    pub fn ingested_schema_version(mut self, value: String) -> Self {
63        self.ingested_schema_version = Some(value);
64        self
65    }
66
67    pub fn ingestion_source(mut self, value: String) -> Self {
68        self.ingestion_source = Some(value);
69        self
70    }
71
72    pub fn last_modified_time(mut self, value: String) -> Self {
73        self.last_modified_time = Some(value);
74        self
75    }
76
77    pub fn origin(mut self, value: String) -> Self {
78        self.origin = Some(value);
79        self
80    }
81
82    pub fn origin_detail(mut self, value: String) -> Self {
83        self.origin_detail = Some(value);
84        self
85    }
86
87    pub fn warnings(
88        mut self,
89        value: Vec<crate::datadogV2::model::ServiceDefinitionMetaWarnings>,
90    ) -> Self {
91        self.warnings = Some(value);
92        self
93    }
94
95    pub fn additional_properties(
96        mut self,
97        value: std::collections::BTreeMap<String, serde_json::Value>,
98    ) -> Self {
99        self.additional_properties = value;
100        self
101    }
102}
103
104impl Default for ServiceDefinitionMeta {
105    fn default() -> Self {
106        Self::new()
107    }
108}
109
110impl<'de> Deserialize<'de> for ServiceDefinitionMeta {
111    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
112    where
113        D: Deserializer<'de>,
114    {
115        struct ServiceDefinitionMetaVisitor;
116        impl<'a> Visitor<'a> for ServiceDefinitionMetaVisitor {
117            type Value = ServiceDefinitionMeta;
118
119            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
120                f.write_str("a mapping")
121            }
122
123            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
124            where
125                M: MapAccess<'a>,
126            {
127                let mut github_html_url: Option<String> = None;
128                let mut ingested_schema_version: Option<String> = None;
129                let mut ingestion_source: Option<String> = None;
130                let mut last_modified_time: Option<String> = None;
131                let mut origin: Option<String> = None;
132                let mut origin_detail: Option<String> = None;
133                let mut warnings: Option<
134                    Vec<crate::datadogV2::model::ServiceDefinitionMetaWarnings>,
135                > = None;
136                let mut additional_properties: std::collections::BTreeMap<
137                    String,
138                    serde_json::Value,
139                > = std::collections::BTreeMap::new();
140                let mut _unparsed = false;
141
142                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
143                    match k.as_str() {
144                        "github-html-url" => {
145                            if v.is_null() {
146                                continue;
147                            }
148                            github_html_url =
149                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
150                        }
151                        "ingested-schema-version" => {
152                            if v.is_null() {
153                                continue;
154                            }
155                            ingested_schema_version =
156                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
157                        }
158                        "ingestion-source" => {
159                            if v.is_null() {
160                                continue;
161                            }
162                            ingestion_source =
163                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
164                        }
165                        "last-modified-time" => {
166                            if v.is_null() {
167                                continue;
168                            }
169                            last_modified_time =
170                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
171                        }
172                        "origin" => {
173                            if v.is_null() {
174                                continue;
175                            }
176                            origin = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
177                        }
178                        "origin-detail" => {
179                            if v.is_null() {
180                                continue;
181                            }
182                            origin_detail =
183                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
184                        }
185                        "warnings" => {
186                            if v.is_null() {
187                                continue;
188                            }
189                            warnings = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
190                        }
191                        &_ => {
192                            if let Ok(value) = serde_json::from_value(v.clone()) {
193                                additional_properties.insert(k, value);
194                            }
195                        }
196                    }
197                }
198
199                let content = ServiceDefinitionMeta {
200                    github_html_url,
201                    ingested_schema_version,
202                    ingestion_source,
203                    last_modified_time,
204                    origin,
205                    origin_detail,
206                    warnings,
207                    additional_properties,
208                    _unparsed,
209                };
210
211                Ok(content)
212            }
213        }
214
215        deserializer.deserialize_any(ServiceDefinitionMetaVisitor)
216    }
217}