datadog_api_client/datadogV2/model/
model_api_key_relationships.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/// Resources related to the API key.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct APIKeyRelationships {
14    /// Relationship to user.
15    #[serde(rename = "created_by")]
16    pub created_by: Option<crate::datadogV2::model::RelationshipToUser>,
17    /// Relationship to user.
18    #[serde(
19        rename = "modified_by",
20        default,
21        with = "::serde_with::rust::double_option"
22    )]
23    pub modified_by: Option<Option<crate::datadogV2::model::NullableRelationshipToUser>>,
24    #[serde(flatten)]
25    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
26    #[serde(skip)]
27    #[serde(default)]
28    pub(crate) _unparsed: bool,
29}
30
31impl APIKeyRelationships {
32    pub fn new() -> APIKeyRelationships {
33        APIKeyRelationships {
34            created_by: None,
35            modified_by: None,
36            additional_properties: std::collections::BTreeMap::new(),
37            _unparsed: false,
38        }
39    }
40
41    pub fn created_by(mut self, value: crate::datadogV2::model::RelationshipToUser) -> Self {
42        self.created_by = Some(value);
43        self
44    }
45
46    pub fn modified_by(
47        mut self,
48        value: Option<crate::datadogV2::model::NullableRelationshipToUser>,
49    ) -> Self {
50        self.modified_by = Some(value);
51        self
52    }
53
54    pub fn additional_properties(
55        mut self,
56        value: std::collections::BTreeMap<String, serde_json::Value>,
57    ) -> Self {
58        self.additional_properties = value;
59        self
60    }
61}
62
63impl Default for APIKeyRelationships {
64    fn default() -> Self {
65        Self::new()
66    }
67}
68
69impl<'de> Deserialize<'de> for APIKeyRelationships {
70    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
71    where
72        D: Deserializer<'de>,
73    {
74        struct APIKeyRelationshipsVisitor;
75        impl<'a> Visitor<'a> for APIKeyRelationshipsVisitor {
76            type Value = APIKeyRelationships;
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 created_by: Option<crate::datadogV2::model::RelationshipToUser> = None;
87                let mut modified_by: Option<
88                    Option<crate::datadogV2::model::NullableRelationshipToUser>,
89                > = 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                        "created_by" => {
99                            if v.is_null() {
100                                continue;
101                            }
102                            created_by = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
103                        }
104                        "modified_by" => {
105                            modified_by =
106                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
107                        }
108                        &_ => {
109                            if let Ok(value) = serde_json::from_value(v.clone()) {
110                                additional_properties.insert(k, value);
111                            }
112                        }
113                    }
114                }
115
116                let content = APIKeyRelationships {
117                    created_by,
118                    modified_by,
119                    additional_properties,
120                    _unparsed,
121                };
122
123                Ok(content)
124            }
125        }
126
127        deserializer.deserialize_any(APIKeyRelationshipsVisitor)
128    }
129}