datadog_api_client/datadogV1/model/
model_webhooks_integration_custom_variable.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 WebhooksIntegrationCustomVariable {
14 #[serde(rename = "is_secret")]
17 pub is_secret: bool,
18 #[serde(rename = "name")]
20 pub name: String,
21 #[serde(rename = "value")]
23 pub value: String,
24 #[serde(flatten)]
25 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
26 #[serde(skip)]
27 #[serde(default)]
28 pub(crate) _unparsed: bool,
29}
30
31impl WebhooksIntegrationCustomVariable {
32 pub fn new(is_secret: bool, name: String, value: String) -> WebhooksIntegrationCustomVariable {
33 WebhooksIntegrationCustomVariable {
34 is_secret,
35 name,
36 value,
37 additional_properties: std::collections::BTreeMap::new(),
38 _unparsed: false,
39 }
40 }
41
42 pub fn additional_properties(
43 mut self,
44 value: std::collections::BTreeMap<String, serde_json::Value>,
45 ) -> Self {
46 self.additional_properties = value;
47 self
48 }
49}
50
51impl<'de> Deserialize<'de> for WebhooksIntegrationCustomVariable {
52 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
53 where
54 D: Deserializer<'de>,
55 {
56 struct WebhooksIntegrationCustomVariableVisitor;
57 impl<'a> Visitor<'a> for WebhooksIntegrationCustomVariableVisitor {
58 type Value = WebhooksIntegrationCustomVariable;
59
60 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
61 f.write_str("a mapping")
62 }
63
64 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
65 where
66 M: MapAccess<'a>,
67 {
68 let mut is_secret: Option<bool> = None;
69 let mut name: Option<String> = None;
70 let mut value: Option<String> = None;
71 let mut additional_properties: std::collections::BTreeMap<
72 String,
73 serde_json::Value,
74 > = std::collections::BTreeMap::new();
75 let mut _unparsed = false;
76
77 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
78 match k.as_str() {
79 "is_secret" => {
80 is_secret = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
81 }
82 "name" => {
83 name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
84 }
85 "value" => {
86 value = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
87 }
88 &_ => {
89 if let Ok(value) = serde_json::from_value(v.clone()) {
90 additional_properties.insert(k, value);
91 }
92 }
93 }
94 }
95 let is_secret = is_secret.ok_or_else(|| M::Error::missing_field("is_secret"))?;
96 let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
97 let value = value.ok_or_else(|| M::Error::missing_field("value"))?;
98
99 let content = WebhooksIntegrationCustomVariable {
100 is_secret,
101 name,
102 value,
103 additional_properties,
104 _unparsed,
105 };
106
107 Ok(content)
108 }
109 }
110
111 deserializer.deserialize_any(WebhooksIntegrationCustomVariableVisitor)
112 }
113}