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