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