datadog_api_client/datadogV2/model/
model_split_integration_update.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/// The definition of the `SplitIntegrationUpdate` object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct SplitIntegrationUpdate {
14    /// The definition of the `SplitCredentialsUpdate` object.
15    #[serde(rename = "credentials")]
16    pub credentials: Option<crate::datadogV2::model::SplitCredentialsUpdate>,
17    /// The definition of the `SplitIntegrationType` object.
18    #[serde(rename = "type")]
19    pub type_: crate::datadogV2::model::SplitIntegrationType,
20    #[serde(flatten)]
21    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22    #[serde(skip)]
23    #[serde(default)]
24    pub(crate) _unparsed: bool,
25}
26
27impl SplitIntegrationUpdate {
28    pub fn new(type_: crate::datadogV2::model::SplitIntegrationType) -> SplitIntegrationUpdate {
29        SplitIntegrationUpdate {
30            credentials: None,
31            type_,
32            additional_properties: std::collections::BTreeMap::new(),
33            _unparsed: false,
34        }
35    }
36
37    pub fn credentials(mut self, value: crate::datadogV2::model::SplitCredentialsUpdate) -> Self {
38        self.credentials = Some(value);
39        self
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 SplitIntegrationUpdate {
52    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
53    where
54        D: Deserializer<'de>,
55    {
56        struct SplitIntegrationUpdateVisitor;
57        impl<'a> Visitor<'a> for SplitIntegrationUpdateVisitor {
58            type Value = SplitIntegrationUpdate;
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 credentials: Option<crate::datadogV2::model::SplitCredentialsUpdate> = None;
69                let mut type_: Option<crate::datadogV2::model::SplitIntegrationType> = None;
70                let mut additional_properties: std::collections::BTreeMap<
71                    String,
72                    serde_json::Value,
73                > = std::collections::BTreeMap::new();
74                let mut _unparsed = false;
75
76                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
77                    match k.as_str() {
78                        "credentials" => {
79                            if v.is_null() {
80                                continue;
81                            }
82                            credentials =
83                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
84                            if let Some(ref _credentials) = credentials {
85                                match _credentials {
86                                    crate::datadogV2::model::SplitCredentialsUpdate::UnparsedObject(_credentials) => {
87                                        _unparsed = true;
88                                    },
89                                    _ => {}
90                                }
91                            }
92                        }
93                        "type" => {
94                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
95                            if let Some(ref _type_) = type_ {
96                                match _type_ {
97                                    crate::datadogV2::model::SplitIntegrationType::UnparsedObject(_type_) => {
98                                        _unparsed = true;
99                                    },
100                                    _ => {}
101                                }
102                            }
103                        }
104                        &_ => {
105                            if let Ok(value) = serde_json::from_value(v.clone()) {
106                                additional_properties.insert(k, value);
107                            }
108                        }
109                    }
110                }
111                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
112
113                let content = SplitIntegrationUpdate {
114                    credentials,
115                    type_,
116                    additional_properties,
117                    _unparsed,
118                };
119
120                Ok(content)
121            }
122        }
123
124        deserializer.deserialize_any(SplitIntegrationUpdateVisitor)
125    }
126}