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