datadog_api_client/datadogV2/model/
model_workflow_data.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 WorkflowData {
14 #[serde(rename = "attributes")]
16 pub attributes: crate::datadogV2::model::WorkflowDataAttributes,
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 WorkflowData {
34 pub fn new(
35 attributes: crate::datadogV2::model::WorkflowDataAttributes,
36 type_: crate::datadogV2::model::WorkflowDataType,
37 ) -> WorkflowData {
38 WorkflowData {
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 WorkflowData {
71 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
72 where
73 D: Deserializer<'de>,
74 {
75 struct WorkflowDataVisitor;
76 impl<'a> Visitor<'a> for WorkflowDataVisitor {
77 type Value = WorkflowData;
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::WorkflowDataAttributes> = None;
88 let mut id: Option<String> = None;
89 let mut relationships: Option<crate::datadogV2::model::WorkflowDataRelationships> =
90 None;
91 let mut type_: Option<crate::datadogV2::model::WorkflowDataType> = None;
92 let mut additional_properties: std::collections::BTreeMap<
93 String,
94 serde_json::Value,
95 > = std::collections::BTreeMap::new();
96 let mut _unparsed = false;
97
98 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
99 match k.as_str() {
100 "attributes" => {
101 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
102 }
103 "id" => {
104 if v.is_null() {
105 continue;
106 }
107 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
108 }
109 "relationships" => {
110 if v.is_null() {
111 continue;
112 }
113 relationships =
114 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
115 }
116 "type" => {
117 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
118 if let Some(ref _type_) = type_ {
119 match _type_ {
120 crate::datadogV2::model::WorkflowDataType::UnparsedObject(
121 _type_,
122 ) => {
123 _unparsed = true;
124 }
125 _ => {}
126 }
127 }
128 }
129 &_ => {
130 if let Ok(value) = serde_json::from_value(v.clone()) {
131 additional_properties.insert(k, value);
132 }
133 }
134 }
135 }
136 let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?;
137 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
138
139 let content = WorkflowData {
140 attributes,
141 id,
142 relationships,
143 type_,
144 additional_properties,
145 _unparsed,
146 };
147
148 Ok(content)
149 }
150 }
151
152 deserializer.deserialize_any(WorkflowDataVisitor)
153 }
154}