datadog_api_client/datadogV2/model/
model_partial_application_key.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct PartialApplicationKey {
14 #[serde(rename = "attributes")]
16 pub attributes: Option<crate::datadogV2::model::PartialApplicationKeyAttributes>,
17 #[serde(rename = "id")]
19 pub id: Option<String>,
20 #[serde(rename = "relationships")]
22 pub relationships: Option<crate::datadogV2::model::ApplicationKeyRelationships>,
23 #[serde(rename = "type")]
25 pub type_: Option<crate::datadogV2::model::ApplicationKeysType>,
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 PartialApplicationKey {
34 pub fn new() -> PartialApplicationKey {
35 PartialApplicationKey {
36 attributes: None,
37 id: None,
38 relationships: None,
39 type_: None,
40 additional_properties: std::collections::BTreeMap::new(),
41 _unparsed: false,
42 }
43 }
44
45 pub fn attributes(
46 mut self,
47 value: crate::datadogV2::model::PartialApplicationKeyAttributes,
48 ) -> Self {
49 self.attributes = Some(value);
50 self
51 }
52
53 pub fn id(mut self, value: String) -> Self {
54 self.id = Some(value);
55 self
56 }
57
58 pub fn relationships(
59 mut self,
60 value: crate::datadogV2::model::ApplicationKeyRelationships,
61 ) -> Self {
62 self.relationships = Some(value);
63 self
64 }
65
66 pub fn type_(mut self, value: crate::datadogV2::model::ApplicationKeysType) -> Self {
67 self.type_ = Some(value);
68 self
69 }
70
71 pub fn additional_properties(
72 mut self,
73 value: std::collections::BTreeMap<String, serde_json::Value>,
74 ) -> Self {
75 self.additional_properties = value;
76 self
77 }
78}
79
80impl Default for PartialApplicationKey {
81 fn default() -> Self {
82 Self::new()
83 }
84}
85
86impl<'de> Deserialize<'de> for PartialApplicationKey {
87 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
88 where
89 D: Deserializer<'de>,
90 {
91 struct PartialApplicationKeyVisitor;
92 impl<'a> Visitor<'a> for PartialApplicationKeyVisitor {
93 type Value = PartialApplicationKey;
94
95 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
96 f.write_str("a mapping")
97 }
98
99 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
100 where
101 M: MapAccess<'a>,
102 {
103 let mut attributes: Option<
104 crate::datadogV2::model::PartialApplicationKeyAttributes,
105 > = None;
106 let mut id: Option<String> = None;
107 let mut relationships: Option<
108 crate::datadogV2::model::ApplicationKeyRelationships,
109 > = None;
110 let mut type_: Option<crate::datadogV2::model::ApplicationKeysType> = None;
111 let mut additional_properties: std::collections::BTreeMap<
112 String,
113 serde_json::Value,
114 > = std::collections::BTreeMap::new();
115 let mut _unparsed = false;
116
117 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
118 match k.as_str() {
119 "attributes" => {
120 if v.is_null() {
121 continue;
122 }
123 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
124 }
125 "id" => {
126 if v.is_null() {
127 continue;
128 }
129 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
130 }
131 "relationships" => {
132 if v.is_null() {
133 continue;
134 }
135 relationships =
136 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
137 }
138 "type" => {
139 if v.is_null() {
140 continue;
141 }
142 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
143 if let Some(ref _type_) = type_ {
144 match _type_ {
145 crate::datadogV2::model::ApplicationKeysType::UnparsedObject(_type_) => {
146 _unparsed = true;
147 },
148 _ => {}
149 }
150 }
151 }
152 &_ => {
153 if let Ok(value) = serde_json::from_value(v.clone()) {
154 additional_properties.insert(k, value);
155 }
156 }
157 }
158 }
159
160 let content = PartialApplicationKey {
161 attributes,
162 id,
163 relationships,
164 type_,
165 additional_properties,
166 _unparsed,
167 };
168
169 Ok(content)
170 }
171 }
172
173 deserializer.deserialize_any(PartialApplicationKeyVisitor)
174 }
175}