datadog_api_client/datadogV2/model/
model_partial_application_key_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 PartialApplicationKeyAttributes {
14 #[serde(rename = "created_at")]
16 pub created_at: Option<String>,
17 #[serde(rename = "last4")]
19 pub last4: Option<String>,
20 #[serde(rename = "name")]
22 pub name: Option<String>,
23 #[serde(rename = "scopes", default, with = "::serde_with::rust::double_option")]
25 pub scopes: Option<Option<Vec<String>>>,
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 PartialApplicationKeyAttributes {
34 pub fn new() -> PartialApplicationKeyAttributes {
35 PartialApplicationKeyAttributes {
36 created_at: None,
37 last4: None,
38 name: None,
39 scopes: None,
40 additional_properties: std::collections::BTreeMap::new(),
41 _unparsed: false,
42 }
43 }
44
45 pub fn created_at(mut self, value: String) -> Self {
46 self.created_at = Some(value);
47 self
48 }
49
50 pub fn last4(mut self, value: String) -> Self {
51 self.last4 = Some(value);
52 self
53 }
54
55 pub fn name(mut self, value: String) -> Self {
56 self.name = Some(value);
57 self
58 }
59
60 pub fn scopes(mut self, value: Option<Vec<String>>) -> Self {
61 self.scopes = Some(value);
62 self
63 }
64
65 pub fn additional_properties(
66 mut self,
67 value: std::collections::BTreeMap<String, serde_json::Value>,
68 ) -> Self {
69 self.additional_properties = value;
70 self
71 }
72}
73
74impl Default for PartialApplicationKeyAttributes {
75 fn default() -> Self {
76 Self::new()
77 }
78}
79
80impl<'de> Deserialize<'de> for PartialApplicationKeyAttributes {
81 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
82 where
83 D: Deserializer<'de>,
84 {
85 struct PartialApplicationKeyAttributesVisitor;
86 impl<'a> Visitor<'a> for PartialApplicationKeyAttributesVisitor {
87 type Value = PartialApplicationKeyAttributes;
88
89 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
90 f.write_str("a mapping")
91 }
92
93 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
94 where
95 M: MapAccess<'a>,
96 {
97 let mut created_at: Option<String> = None;
98 let mut last4: Option<String> = None;
99 let mut name: Option<String> = None;
100 let mut scopes: Option<Option<Vec<String>>> = None;
101 let mut additional_properties: std::collections::BTreeMap<
102 String,
103 serde_json::Value,
104 > = std::collections::BTreeMap::new();
105 let mut _unparsed = false;
106
107 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
108 match k.as_str() {
109 "created_at" => {
110 if v.is_null() {
111 continue;
112 }
113 created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114 }
115 "last4" => {
116 if v.is_null() {
117 continue;
118 }
119 last4 = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
120 }
121 "name" => {
122 if v.is_null() {
123 continue;
124 }
125 name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
126 }
127 "scopes" => {
128 scopes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
129 }
130 &_ => {
131 if let Ok(value) = serde_json::from_value(v.clone()) {
132 additional_properties.insert(k, value);
133 }
134 }
135 }
136 }
137
138 let content = PartialApplicationKeyAttributes {
139 created_at,
140 last4,
141 name,
142 scopes,
143 additional_properties,
144 _unparsed,
145 };
146
147 Ok(content)
148 }
149 }
150
151 deserializer.deserialize_any(PartialApplicationKeyAttributesVisitor)
152 }
153}