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