datadog_api_client/datadogV2/model/
model_ci_app_event_attributes.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 CIAppEventAttributes {
14 #[serde(rename = "attributes")]
16 pub attributes: Option<std::collections::BTreeMap<String, serde_json::Value>>,
17 #[serde(rename = "tags")]
19 pub tags: Option<Vec<String>>,
20 #[serde(rename = "test_level")]
22 pub test_level: Option<crate::datadogV2::model::CIAppTestLevel>,
23 #[serde(flatten)]
24 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25 #[serde(skip)]
26 #[serde(default)]
27 pub(crate) _unparsed: bool,
28}
29
30impl CIAppEventAttributes {
31 pub fn new() -> CIAppEventAttributes {
32 CIAppEventAttributes {
33 attributes: None,
34 tags: None,
35 test_level: None,
36 additional_properties: std::collections::BTreeMap::new(),
37 _unparsed: false,
38 }
39 }
40
41 pub fn attributes(
42 mut self,
43 value: std::collections::BTreeMap<String, serde_json::Value>,
44 ) -> Self {
45 self.attributes = Some(value);
46 self
47 }
48
49 pub fn tags(mut self, value: Vec<String>) -> Self {
50 self.tags = Some(value);
51 self
52 }
53
54 pub fn test_level(mut self, value: crate::datadogV2::model::CIAppTestLevel) -> Self {
55 self.test_level = Some(value);
56 self
57 }
58
59 pub fn additional_properties(
60 mut self,
61 value: std::collections::BTreeMap<String, serde_json::Value>,
62 ) -> Self {
63 self.additional_properties = value;
64 self
65 }
66}
67
68impl Default for CIAppEventAttributes {
69 fn default() -> Self {
70 Self::new()
71 }
72}
73
74impl<'de> Deserialize<'de> for CIAppEventAttributes {
75 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
76 where
77 D: Deserializer<'de>,
78 {
79 struct CIAppEventAttributesVisitor;
80 impl<'a> Visitor<'a> for CIAppEventAttributesVisitor {
81 type Value = CIAppEventAttributes;
82
83 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
84 f.write_str("a mapping")
85 }
86
87 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
88 where
89 M: MapAccess<'a>,
90 {
91 let mut attributes: Option<std::collections::BTreeMap<String, serde_json::Value>> =
92 None;
93 let mut tags: Option<Vec<String>> = None;
94 let mut test_level: Option<crate::datadogV2::model::CIAppTestLevel> = None;
95 let mut additional_properties: std::collections::BTreeMap<
96 String,
97 serde_json::Value,
98 > = std::collections::BTreeMap::new();
99 let mut _unparsed = false;
100
101 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
102 match k.as_str() {
103 "attributes" => {
104 if v.is_null() {
105 continue;
106 }
107 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
108 }
109 "tags" => {
110 if v.is_null() {
111 continue;
112 }
113 tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114 }
115 "test_level" => {
116 if v.is_null() {
117 continue;
118 }
119 test_level = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
120 if let Some(ref _test_level) = test_level {
121 match _test_level {
122 crate::datadogV2::model::CIAppTestLevel::UnparsedObject(
123 _test_level,
124 ) => {
125 _unparsed = true;
126 }
127 _ => {}
128 }
129 }
130 }
131 &_ => {
132 if let Ok(value) = serde_json::from_value(v.clone()) {
133 additional_properties.insert(k, value);
134 }
135 }
136 }
137 }
138
139 let content = CIAppEventAttributes {
140 attributes,
141 tags,
142 test_level,
143 additional_properties,
144 _unparsed,
145 };
146
147 Ok(content)
148 }
149 }
150
151 deserializer.deserialize_any(CIAppEventAttributesVisitor)
152 }
153}