datadog_api_client/datadogV2/model/
model_partial_application_key_response.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/// Response for retrieving a partial application key.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct PartialApplicationKeyResponse {
14    /// Partial Datadog application key.
15    #[serde(rename = "data")]
16    pub data: Option<crate::datadogV2::model::PartialApplicationKey>,
17    /// Array of objects related to the application key.
18    #[serde(rename = "included")]
19    pub included: Option<Vec<crate::datadogV2::model::ApplicationKeyResponseIncludedItem>>,
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 PartialApplicationKeyResponse {
28    pub fn new() -> PartialApplicationKeyResponse {
29        PartialApplicationKeyResponse {
30            data: None,
31            included: None,
32            additional_properties: std::collections::BTreeMap::new(),
33            _unparsed: false,
34        }
35    }
36
37    pub fn data(mut self, value: crate::datadogV2::model::PartialApplicationKey) -> Self {
38        self.data = Some(value);
39        self
40    }
41
42    pub fn included(
43        mut self,
44        value: Vec<crate::datadogV2::model::ApplicationKeyResponseIncludedItem>,
45    ) -> Self {
46        self.included = Some(value);
47        self
48    }
49
50    pub fn additional_properties(
51        mut self,
52        value: std::collections::BTreeMap<String, serde_json::Value>,
53    ) -> Self {
54        self.additional_properties = value;
55        self
56    }
57}
58
59impl Default for PartialApplicationKeyResponse {
60    fn default() -> Self {
61        Self::new()
62    }
63}
64
65impl<'de> Deserialize<'de> for PartialApplicationKeyResponse {
66    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67    where
68        D: Deserializer<'de>,
69    {
70        struct PartialApplicationKeyResponseVisitor;
71        impl<'a> Visitor<'a> for PartialApplicationKeyResponseVisitor {
72            type Value = PartialApplicationKeyResponse;
73
74            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
75                f.write_str("a mapping")
76            }
77
78            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
79            where
80                M: MapAccess<'a>,
81            {
82                let mut data: Option<crate::datadogV2::model::PartialApplicationKey> = None;
83                let mut included: Option<
84                    Vec<crate::datadogV2::model::ApplicationKeyResponseIncludedItem>,
85                > = None;
86                let mut additional_properties: std::collections::BTreeMap<
87                    String,
88                    serde_json::Value,
89                > = std::collections::BTreeMap::new();
90                let mut _unparsed = false;
91
92                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
93                    match k.as_str() {
94                        "data" => {
95                            if v.is_null() {
96                                continue;
97                            }
98                            data = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
99                        }
100                        "included" => {
101                            if v.is_null() {
102                                continue;
103                            }
104                            included = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
105                        }
106                        &_ => {
107                            if let Ok(value) = serde_json::from_value(v.clone()) {
108                                additional_properties.insert(k, value);
109                            }
110                        }
111                    }
112                }
113
114                let content = PartialApplicationKeyResponse {
115                    data,
116                    included,
117                    additional_properties,
118                    _unparsed,
119                };
120
121                Ok(content)
122            }
123        }
124
125        deserializer.deserialize_any(PartialApplicationKeyResponseVisitor)
126    }
127}