datadog_api_client/datadogV2/model/
model_get_app_response.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// The full app definition response object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct GetAppResponse {
14    /// The data object containing the app definition.
15    #[serde(rename = "data")]
16    pub data: Option<crate::datadogV2::model::GetAppResponseData>,
17    /// Data on the version of the app that was published.
18    #[serde(rename = "included")]
19    pub included: Option<Vec<crate::datadogV2::model::Deployment>>,
20    /// Metadata of an app.
21    #[serde(rename = "meta")]
22    pub meta: Option<crate::datadogV2::model::AppMeta>,
23    /// The app's publication relationship and custom connections.
24    #[serde(rename = "relationship")]
25    pub relationship: Option<crate::datadogV2::model::AppRelationship>,
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 GetAppResponse {
34    pub fn new() -> GetAppResponse {
35        GetAppResponse {
36            data: None,
37            included: None,
38            meta: None,
39            relationship: None,
40            additional_properties: std::collections::BTreeMap::new(),
41            _unparsed: false,
42        }
43    }
44
45    pub fn data(mut self, value: crate::datadogV2::model::GetAppResponseData) -> Self {
46        self.data = Some(value);
47        self
48    }
49
50    pub fn included(mut self, value: Vec<crate::datadogV2::model::Deployment>) -> Self {
51        self.included = Some(value);
52        self
53    }
54
55    pub fn meta(mut self, value: crate::datadogV2::model::AppMeta) -> Self {
56        self.meta = Some(value);
57        self
58    }
59
60    pub fn relationship(mut self, value: crate::datadogV2::model::AppRelationship) -> Self {
61        self.relationship = 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 GetAppResponse {
75    fn default() -> Self {
76        Self::new()
77    }
78}
79
80impl<'de> Deserialize<'de> for GetAppResponse {
81    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
82    where
83        D: Deserializer<'de>,
84    {
85        struct GetAppResponseVisitor;
86        impl<'a> Visitor<'a> for GetAppResponseVisitor {
87            type Value = GetAppResponse;
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 data: Option<crate::datadogV2::model::GetAppResponseData> = None;
98                let mut included: Option<Vec<crate::datadogV2::model::Deployment>> = None;
99                let mut meta: Option<crate::datadogV2::model::AppMeta> = None;
100                let mut relationship: Option<crate::datadogV2::model::AppRelationship> = 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                        "data" => {
110                            if v.is_null() {
111                                continue;
112                            }
113                            data = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114                        }
115                        "included" => {
116                            if v.is_null() {
117                                continue;
118                            }
119                            included = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
120                        }
121                        "meta" => {
122                            if v.is_null() {
123                                continue;
124                            }
125                            meta = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
126                        }
127                        "relationship" => {
128                            if v.is_null() {
129                                continue;
130                            }
131                            relationship =
132                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
133                        }
134                        &_ => {
135                            if let Ok(value) = serde_json::from_value(v.clone()) {
136                                additional_properties.insert(k, value);
137                            }
138                        }
139                    }
140                }
141
142                let content = GetAppResponse {
143                    data,
144                    included,
145                    meta,
146                    relationship,
147                    additional_properties,
148                    _unparsed,
149                };
150
151                Ok(content)
152            }
153        }
154
155        deserializer.deserialize_any(GetAppResponseVisitor)
156    }
157}