datadog_api_client/datadogV2/model/
model_org_connection_update_attributes.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/// Attributes for updating an org connection.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct OrgConnectionUpdateAttributes {
14    /// Updated list of connection types.
15    #[serde(rename = "connection_types")]
16    pub connection_types: Vec<crate::datadogV2::model::OrgConnectionTypeEnum>,
17    #[serde(flatten)]
18    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
19    #[serde(skip)]
20    #[serde(default)]
21    pub(crate) _unparsed: bool,
22}
23
24impl OrgConnectionUpdateAttributes {
25    pub fn new(
26        connection_types: Vec<crate::datadogV2::model::OrgConnectionTypeEnum>,
27    ) -> OrgConnectionUpdateAttributes {
28        OrgConnectionUpdateAttributes {
29            connection_types,
30            additional_properties: std::collections::BTreeMap::new(),
31            _unparsed: false,
32        }
33    }
34
35    pub fn additional_properties(
36        mut self,
37        value: std::collections::BTreeMap<String, serde_json::Value>,
38    ) -> Self {
39        self.additional_properties = value;
40        self
41    }
42}
43
44impl<'de> Deserialize<'de> for OrgConnectionUpdateAttributes {
45    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
46    where
47        D: Deserializer<'de>,
48    {
49        struct OrgConnectionUpdateAttributesVisitor;
50        impl<'a> Visitor<'a> for OrgConnectionUpdateAttributesVisitor {
51            type Value = OrgConnectionUpdateAttributes;
52
53            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
54                f.write_str("a mapping")
55            }
56
57            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
58            where
59                M: MapAccess<'a>,
60            {
61                let mut connection_types: Option<
62                    Vec<crate::datadogV2::model::OrgConnectionTypeEnum>,
63                > = None;
64                let mut additional_properties: std::collections::BTreeMap<
65                    String,
66                    serde_json::Value,
67                > = std::collections::BTreeMap::new();
68                let mut _unparsed = false;
69
70                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
71                    match k.as_str() {
72                        "connection_types" => {
73                            connection_types =
74                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
75                        }
76                        &_ => {
77                            if let Ok(value) = serde_json::from_value(v.clone()) {
78                                additional_properties.insert(k, value);
79                            }
80                        }
81                    }
82                }
83                let connection_types =
84                    connection_types.ok_or_else(|| M::Error::missing_field("connection_types"))?;
85
86                let content = OrgConnectionUpdateAttributes {
87                    connection_types,
88                    additional_properties,
89                    _unparsed,
90                };
91
92                Ok(content)
93            }
94        }
95
96        deserializer.deserialize_any(OrgConnectionUpdateAttributesVisitor)
97    }
98}