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