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