datadog_api_client/datadogV2/model/
model_ci_app_pipeline_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 CIAppPipelineEventAttributes {
14 #[serde(rename = "attributes")]
16 pub attributes: Option<std::collections::BTreeMap<String, serde_json::Value>>,
17 #[serde(rename = "ci_level")]
19 pub ci_level: Option<crate::datadogV2::model::CIAppPipelineLevel>,
20 #[serde(rename = "tags")]
22 pub tags: Option<Vec<String>>,
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 CIAppPipelineEventAttributes {
31 pub fn new() -> CIAppPipelineEventAttributes {
32 CIAppPipelineEventAttributes {
33 attributes: None,
34 ci_level: None,
35 tags: 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 ci_level(mut self, value: crate::datadogV2::model::CIAppPipelineLevel) -> Self {
50 self.ci_level = Some(value);
51 self
52 }
53
54 pub fn tags(mut self, value: Vec<String>) -> Self {
55 self.tags = 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 CIAppPipelineEventAttributes {
69 fn default() -> Self {
70 Self::new()
71 }
72}
73
74impl<'de> Deserialize<'de> for CIAppPipelineEventAttributes {
75 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
76 where
77 D: Deserializer<'de>,
78 {
79 struct CIAppPipelineEventAttributesVisitor;
80 impl<'a> Visitor<'a> for CIAppPipelineEventAttributesVisitor {
81 type Value = CIAppPipelineEventAttributes;
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 ci_level: Option<crate::datadogV2::model::CIAppPipelineLevel> = None;
94 let mut tags: Option<Vec<String>> = 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 "ci_level" => {
110 if v.is_null() {
111 continue;
112 }
113 ci_level = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114 if let Some(ref _ci_level) = ci_level {
115 match _ci_level {
116 crate::datadogV2::model::CIAppPipelineLevel::UnparsedObject(
117 _ci_level,
118 ) => {
119 _unparsed = true;
120 }
121 _ => {}
122 }
123 }
124 }
125 "tags" => {
126 if v.is_null() {
127 continue;
128 }
129 tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
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 = CIAppPipelineEventAttributes {
140 attributes,
141 ci_level,
142 tags,
143 additional_properties,
144 _unparsed,
145 };
146
147 Ok(content)
148 }
149 }
150
151 deserializer.deserialize_any(CIAppPipelineEventAttributesVisitor)
152 }
153}