datadog_api_client/datadogV1/model/
model_webhooks_integration_update_request.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// Update request of a Webhooks integration object.
10///
11/// *All properties are optional.*
12#[non_exhaustive]
13#[skip_serializing_none]
14#[derive(Clone, Debug, PartialEq, Serialize)]
15pub struct WebhooksIntegrationUpdateRequest {
16    /// If `null`, uses no header.
17    /// If given a JSON payload, these will be headers attached to your webhook.
18    #[serde(rename = "custom_headers")]
19    pub custom_headers: Option<String>,
20    /// Encoding type. Can be given either `json` or `form`.
21    #[serde(rename = "encode_as")]
22    pub encode_as: Option<crate::datadogV1::model::WebhooksIntegrationEncoding>,
23    /// The name of the webhook. It corresponds with `<WEBHOOK_NAME>`.
24    /// Learn more on how to use it in
25    /// [monitor notifications](<https://docs.datadoghq.com/monitors/notify>).
26    #[serde(rename = "name")]
27    pub name: Option<String>,
28    /// If `null`, uses the default payload.
29    /// If given a JSON payload, the webhook returns the payload
30    /// specified by the given payload.
31    /// [Webhooks variable usage](<https://docs.datadoghq.com/integrations/webhooks/#usage>).
32    #[serde(
33        rename = "payload",
34        default,
35        with = "::serde_with::rust::double_option"
36    )]
37    pub payload: Option<Option<String>>,
38    /// URL of the webhook.
39    #[serde(rename = "url")]
40    pub url: Option<String>,
41    #[serde(flatten)]
42    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
43    #[serde(skip)]
44    #[serde(default)]
45    pub(crate) _unparsed: bool,
46}
47
48impl WebhooksIntegrationUpdateRequest {
49    pub fn new() -> WebhooksIntegrationUpdateRequest {
50        WebhooksIntegrationUpdateRequest {
51            custom_headers: None,
52            encode_as: None,
53            name: None,
54            payload: None,
55            url: None,
56            additional_properties: std::collections::BTreeMap::new(),
57            _unparsed: false,
58        }
59    }
60
61    pub fn custom_headers(mut self, value: String) -> Self {
62        self.custom_headers = Some(value);
63        self
64    }
65
66    pub fn encode_as(
67        mut self,
68        value: crate::datadogV1::model::WebhooksIntegrationEncoding,
69    ) -> Self {
70        self.encode_as = Some(value);
71        self
72    }
73
74    pub fn name(mut self, value: String) -> Self {
75        self.name = Some(value);
76        self
77    }
78
79    pub fn payload(mut self, value: Option<String>) -> Self {
80        self.payload = Some(value);
81        self
82    }
83
84    pub fn url(mut self, value: String) -> Self {
85        self.url = Some(value);
86        self
87    }
88
89    pub fn additional_properties(
90        mut self,
91        value: std::collections::BTreeMap<String, serde_json::Value>,
92    ) -> Self {
93        self.additional_properties = value;
94        self
95    }
96}
97
98impl Default for WebhooksIntegrationUpdateRequest {
99    fn default() -> Self {
100        Self::new()
101    }
102}
103
104impl<'de> Deserialize<'de> for WebhooksIntegrationUpdateRequest {
105    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
106    where
107        D: Deserializer<'de>,
108    {
109        struct WebhooksIntegrationUpdateRequestVisitor;
110        impl<'a> Visitor<'a> for WebhooksIntegrationUpdateRequestVisitor {
111            type Value = WebhooksIntegrationUpdateRequest;
112
113            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
114                f.write_str("a mapping")
115            }
116
117            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
118            where
119                M: MapAccess<'a>,
120            {
121                let mut custom_headers: Option<String> = None;
122                let mut encode_as: Option<crate::datadogV1::model::WebhooksIntegrationEncoding> =
123                    None;
124                let mut name: Option<String> = None;
125                let mut payload: Option<Option<String>> = None;
126                let mut url: Option<String> = None;
127                let mut additional_properties: std::collections::BTreeMap<
128                    String,
129                    serde_json::Value,
130                > = std::collections::BTreeMap::new();
131                let mut _unparsed = false;
132
133                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
134                    match k.as_str() {
135                        "custom_headers" => {
136                            if v.is_null() {
137                                continue;
138                            }
139                            custom_headers =
140                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
141                        }
142                        "encode_as" => {
143                            if v.is_null() {
144                                continue;
145                            }
146                            encode_as = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
147                            if let Some(ref _encode_as) = encode_as {
148                                match _encode_as {
149                                    crate::datadogV1::model::WebhooksIntegrationEncoding::UnparsedObject(_encode_as) => {
150                                        _unparsed = true;
151                                    },
152                                    _ => {}
153                                }
154                            }
155                        }
156                        "name" => {
157                            if v.is_null() {
158                                continue;
159                            }
160                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
161                        }
162                        "payload" => {
163                            payload = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
164                        }
165                        "url" => {
166                            if v.is_null() {
167                                continue;
168                            }
169                            url = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
170                        }
171                        &_ => {
172                            if let Ok(value) = serde_json::from_value(v.clone()) {
173                                additional_properties.insert(k, value);
174                            }
175                        }
176                    }
177                }
178
179                let content = WebhooksIntegrationUpdateRequest {
180                    custom_headers,
181                    encode_as,
182                    name,
183                    payload,
184                    url,
185                    additional_properties,
186                    _unparsed,
187                };
188
189                Ok(content)
190            }
191        }
192
193        deserializer.deserialize_any(WebhooksIntegrationUpdateRequestVisitor)
194    }
195}