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