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