datadog_api_client/datadogV2/model/
model_application_key_update_attributes.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 ApplicationKeyUpdateAttributes {
14 #[serde(rename = "name")]
16 pub name: Option<String>,
17 #[serde(rename = "scopes", default, with = "::serde_with::rust::double_option")]
19 pub scopes: Option<Option<Vec<String>>>,
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 ApplicationKeyUpdateAttributes {
28 pub fn new() -> ApplicationKeyUpdateAttributes {
29 ApplicationKeyUpdateAttributes {
30 name: None,
31 scopes: None,
32 additional_properties: std::collections::BTreeMap::new(),
33 _unparsed: false,
34 }
35 }
36
37 pub fn name(mut self, value: String) -> Self {
38 self.name = Some(value);
39 self
40 }
41
42 pub fn scopes(mut self, value: Option<Vec<String>>) -> Self {
43 self.scopes = Some(value);
44 self
45 }
46
47 pub fn additional_properties(
48 mut self,
49 value: std::collections::BTreeMap<String, serde_json::Value>,
50 ) -> Self {
51 self.additional_properties = value;
52 self
53 }
54}
55
56impl Default for ApplicationKeyUpdateAttributes {
57 fn default() -> Self {
58 Self::new()
59 }
60}
61
62impl<'de> Deserialize<'de> for ApplicationKeyUpdateAttributes {
63 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
64 where
65 D: Deserializer<'de>,
66 {
67 struct ApplicationKeyUpdateAttributesVisitor;
68 impl<'a> Visitor<'a> for ApplicationKeyUpdateAttributesVisitor {
69 type Value = ApplicationKeyUpdateAttributes;
70
71 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
72 f.write_str("a mapping")
73 }
74
75 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
76 where
77 M: MapAccess<'a>,
78 {
79 let mut name: Option<String> = None;
80 let mut scopes: Option<Option<Vec<String>>> = None;
81 let mut additional_properties: std::collections::BTreeMap<
82 String,
83 serde_json::Value,
84 > = std::collections::BTreeMap::new();
85 let mut _unparsed = false;
86
87 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
88 match k.as_str() {
89 "name" => {
90 if v.is_null() {
91 continue;
92 }
93 name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
94 }
95 "scopes" => {
96 scopes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
97 }
98 &_ => {
99 if let Ok(value) = serde_json::from_value(v.clone()) {
100 additional_properties.insert(k, value);
101 }
102 }
103 }
104 }
105
106 let content = ApplicationKeyUpdateAttributes {
107 name,
108 scopes,
109 additional_properties,
110 _unparsed,
111 };
112
113 Ok(content)
114 }
115 }
116
117 deserializer.deserialize_any(ApplicationKeyUpdateAttributesVisitor)
118 }
119}