datadog_api_client/datadogV2/model/
model_get_app_response_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 GetAppResponseData {
14 #[serde(rename = "attributes")]
16 pub attributes: crate::datadogV2::model::GetAppResponseDataAttributes,
17 #[serde(rename = "id")]
19 pub id: uuid::Uuid,
20 #[serde(rename = "type")]
22 pub type_: crate::datadogV2::model::AppDefinitionType,
23 #[serde(flatten)]
24 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25 #[serde(skip)]
26 #[serde(default)]
27 pub(crate) _unparsed: bool,
28}
29
30impl GetAppResponseData {
31 pub fn new(
32 attributes: crate::datadogV2::model::GetAppResponseDataAttributes,
33 id: uuid::Uuid,
34 type_: crate::datadogV2::model::AppDefinitionType,
35 ) -> GetAppResponseData {
36 GetAppResponseData {
37 attributes,
38 id,
39 type_,
40 additional_properties: std::collections::BTreeMap::new(),
41 _unparsed: false,
42 }
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 GetAppResponseData {
55 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
56 where
57 D: Deserializer<'de>,
58 {
59 struct GetAppResponseDataVisitor;
60 impl<'a> Visitor<'a> for GetAppResponseDataVisitor {
61 type Value = GetAppResponseData;
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<crate::datadogV2::model::GetAppResponseDataAttributes> =
72 None;
73 let mut id: Option<uuid::Uuid> = 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 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
85 }
86 "id" => {
87 id = 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 attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?;
110 let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
111 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
112
113 let content = GetAppResponseData {
114 attributes,
115 id,
116 type_,
117 additional_properties,
118 _unparsed,
119 };
120
121 Ok(content)
122 }
123 }
124
125 deserializer.deserialize_any(GetAppResponseDataVisitor)
126 }
127}