datadog_api_client/datadogV2/model/
model_gitlab_api_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 `GitlabAPIKey` object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct GitlabAPIKeyUpdate {
14    /// The `GitlabAPIKeyUpdate` `api_token`.
15    #[serde(rename = "api_token")]
16    pub api_token: Option<String>,
17    /// The definition of the `GitlabAPIKey` object.
18    #[serde(rename = "type")]
19    pub type_: crate::datadogV2::model::GitlabAPIKeyType,
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 GitlabAPIKeyUpdate {
28    pub fn new(type_: crate::datadogV2::model::GitlabAPIKeyType) -> GitlabAPIKeyUpdate {
29        GitlabAPIKeyUpdate {
30            api_token: None,
31            type_,
32            additional_properties: std::collections::BTreeMap::new(),
33            _unparsed: false,
34        }
35    }
36
37    pub fn api_token(mut self, value: String) -> Self {
38        self.api_token = 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 GitlabAPIKeyUpdate {
52    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
53    where
54        D: Deserializer<'de>,
55    {
56        struct GitlabAPIKeyUpdateVisitor;
57        impl<'a> Visitor<'a> for GitlabAPIKeyUpdateVisitor {
58            type Value = GitlabAPIKeyUpdate;
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 api_token: Option<String> = None;
69                let mut type_: Option<crate::datadogV2::model::GitlabAPIKeyType> = 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                        "api_token" => {
79                            if v.is_null() {
80                                continue;
81                            }
82                            api_token = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
83                        }
84                        "type" => {
85                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
86                            if let Some(ref _type_) = type_ {
87                                match _type_ {
88                                    crate::datadogV2::model::GitlabAPIKeyType::UnparsedObject(
89                                        _type_,
90                                    ) => {
91                                        _unparsed = true;
92                                    }
93                                    _ => {}
94                                }
95                            }
96                        }
97                        &_ => {
98                            if let Ok(value) = serde_json::from_value(v.clone()) {
99                                additional_properties.insert(k, value);
100                            }
101                        }
102                    }
103                }
104                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
105
106                let content = GitlabAPIKeyUpdate {
107                    api_token,
108                    type_,
109                    additional_properties,
110                    _unparsed,
111                };
112
113                Ok(content)
114            }
115        }
116
117        deserializer.deserialize_any(GitlabAPIKeyUpdateVisitor)
118    }
119}