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