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