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