datadog_api_client/datadogV2/model/
model_update_app_request_data.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 data object containing the new app definition. Any fields not included in the request remain unchanged.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct UpdateAppRequestData {
14    /// App definition attributes to be updated, such as name, description, and components.
15    #[serde(rename = "attributes")]
16    pub attributes: Option<crate::datadogV2::model::UpdateAppRequestDataAttributes>,
17    /// The ID of the app to update. The app ID must match the ID in the URL path.
18    #[serde(rename = "id")]
19    pub id: Option<uuid::Uuid>,
20    /// The app definition type.
21    #[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 UpdateAppRequestData {
31    pub fn new(type_: crate::datadogV2::model::AppDefinitionType) -> UpdateAppRequestData {
32        UpdateAppRequestData {
33            attributes: None,
34            id: None,
35            type_,
36            additional_properties: std::collections::BTreeMap::new(),
37            _unparsed: false,
38        }
39    }
40
41    pub fn attributes(
42        mut self,
43        value: crate::datadogV2::model::UpdateAppRequestDataAttributes,
44    ) -> Self {
45        self.attributes = Some(value);
46        self
47    }
48
49    pub fn id(mut self, value: uuid::Uuid) -> Self {
50        self.id = Some(value);
51        self
52    }
53
54    pub fn additional_properties(
55        mut self,
56        value: std::collections::BTreeMap<String, serde_json::Value>,
57    ) -> Self {
58        self.additional_properties = value;
59        self
60    }
61}
62
63impl<'de> Deserialize<'de> for UpdateAppRequestData {
64    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
65    where
66        D: Deserializer<'de>,
67    {
68        struct UpdateAppRequestDataVisitor;
69        impl<'a> Visitor<'a> for UpdateAppRequestDataVisitor {
70            type Value = UpdateAppRequestData;
71
72            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
73                f.write_str("a mapping")
74            }
75
76            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
77            where
78                M: MapAccess<'a>,
79            {
80                let mut attributes: Option<
81                    crate::datadogV2::model::UpdateAppRequestDataAttributes,
82                > = None;
83                let mut id: Option<uuid::Uuid> = None;
84                let mut type_: Option<crate::datadogV2::model::AppDefinitionType> = None;
85                let mut additional_properties: std::collections::BTreeMap<
86                    String,
87                    serde_json::Value,
88                > = std::collections::BTreeMap::new();
89                let mut _unparsed = false;
90
91                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
92                    match k.as_str() {
93                        "attributes" => {
94                            if v.is_null() {
95                                continue;
96                            }
97                            attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
98                        }
99                        "id" => {
100                            if v.is_null() {
101                                continue;
102                            }
103                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
104                        }
105                        "type" => {
106                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
107                            if let Some(ref _type_) = type_ {
108                                match _type_ {
109                                    crate::datadogV2::model::AppDefinitionType::UnparsedObject(
110                                        _type_,
111                                    ) => {
112                                        _unparsed = true;
113                                    }
114                                    _ => {}
115                                }
116                            }
117                        }
118                        &_ => {
119                            if let Ok(value) = serde_json::from_value(v.clone()) {
120                                additional_properties.insert(k, value);
121                            }
122                        }
123                    }
124                }
125                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
126
127                let content = UpdateAppRequestData {
128                    attributes,
129                    id,
130                    type_,
131                    additional_properties,
132                    _unparsed,
133                };
134
135                Ok(content)
136            }
137        }
138
139        deserializer.deserialize_any(UpdateAppRequestDataVisitor)
140    }
141}