datadog_api_client/datadogV2/model/
model_patch_table_request_data_attributes.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 definition of `PatchTableRequestDataAttributes` object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct PatchTableRequestDataAttributes {
14    /// The description of the reference table.
15    #[serde(rename = "description")]
16    pub description: Option<String>,
17    /// The definition of `PatchTableRequestDataAttributesFileMetadata` object.
18    #[serde(rename = "file_metadata")]
19    pub file_metadata: Option<crate::datadogV2::model::PatchTableRequestDataAttributesFileMetadata>,
20    /// The definition of `PatchTableRequestDataAttributesSchema` object.
21    #[serde(rename = "schema")]
22    pub schema: Option<crate::datadogV2::model::PatchTableRequestDataAttributesSchema>,
23    /// Whether this table is synced automatically.
24    #[serde(rename = "sync_enabled")]
25    pub sync_enabled: Option<bool>,
26    /// The tags of the reference table.
27    #[serde(rename = "tags")]
28    pub tags: Option<Vec<String>>,
29    #[serde(flatten)]
30    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
31    #[serde(skip)]
32    #[serde(default)]
33    pub(crate) _unparsed: bool,
34}
35
36impl PatchTableRequestDataAttributes {
37    pub fn new() -> PatchTableRequestDataAttributes {
38        PatchTableRequestDataAttributes {
39            description: None,
40            file_metadata: None,
41            schema: None,
42            sync_enabled: None,
43            tags: None,
44            additional_properties: std::collections::BTreeMap::new(),
45            _unparsed: false,
46        }
47    }
48
49    pub fn description(mut self, value: String) -> Self {
50        self.description = Some(value);
51        self
52    }
53
54    pub fn file_metadata(
55        mut self,
56        value: crate::datadogV2::model::PatchTableRequestDataAttributesFileMetadata,
57    ) -> Self {
58        self.file_metadata = Some(value);
59        self
60    }
61
62    pub fn schema(
63        mut self,
64        value: crate::datadogV2::model::PatchTableRequestDataAttributesSchema,
65    ) -> Self {
66        self.schema = Some(value);
67        self
68    }
69
70    pub fn sync_enabled(mut self, value: bool) -> Self {
71        self.sync_enabled = Some(value);
72        self
73    }
74
75    pub fn tags(mut self, value: Vec<String>) -> Self {
76        self.tags = Some(value);
77        self
78    }
79
80    pub fn additional_properties(
81        mut self,
82        value: std::collections::BTreeMap<String, serde_json::Value>,
83    ) -> Self {
84        self.additional_properties = value;
85        self
86    }
87}
88
89impl Default for PatchTableRequestDataAttributes {
90    fn default() -> Self {
91        Self::new()
92    }
93}
94
95impl<'de> Deserialize<'de> for PatchTableRequestDataAttributes {
96    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
97    where
98        D: Deserializer<'de>,
99    {
100        struct PatchTableRequestDataAttributesVisitor;
101        impl<'a> Visitor<'a> for PatchTableRequestDataAttributesVisitor {
102            type Value = PatchTableRequestDataAttributes;
103
104            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
105                f.write_str("a mapping")
106            }
107
108            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
109            where
110                M: MapAccess<'a>,
111            {
112                let mut description: Option<String> = None;
113                let mut file_metadata: Option<
114                    crate::datadogV2::model::PatchTableRequestDataAttributesFileMetadata,
115                > = None;
116                let mut schema: Option<
117                    crate::datadogV2::model::PatchTableRequestDataAttributesSchema,
118                > = None;
119                let mut sync_enabled: Option<bool> = None;
120                let mut tags: Option<Vec<String>> = None;
121                let mut additional_properties: std::collections::BTreeMap<
122                    String,
123                    serde_json::Value,
124                > = std::collections::BTreeMap::new();
125                let mut _unparsed = false;
126
127                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
128                    match k.as_str() {
129                        "description" => {
130                            if v.is_null() {
131                                continue;
132                            }
133                            description =
134                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
135                        }
136                        "file_metadata" => {
137                            if v.is_null() {
138                                continue;
139                            }
140                            file_metadata =
141                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
142                            if let Some(ref _file_metadata) = file_metadata {
143                                match _file_metadata {
144                                    crate::datadogV2::model::PatchTableRequestDataAttributesFileMetadata::UnparsedObject(_file_metadata) => {
145                                        _unparsed = true;
146                                    },
147                                    _ => {}
148                                }
149                            }
150                        }
151                        "schema" => {
152                            if v.is_null() {
153                                continue;
154                            }
155                            schema = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
156                        }
157                        "sync_enabled" => {
158                            if v.is_null() {
159                                continue;
160                            }
161                            sync_enabled =
162                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
163                        }
164                        "tags" => {
165                            if v.is_null() {
166                                continue;
167                            }
168                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
169                        }
170                        &_ => {
171                            if let Ok(value) = serde_json::from_value(v.clone()) {
172                                additional_properties.insert(k, value);
173                            }
174                        }
175                    }
176                }
177
178                let content = PatchTableRequestDataAttributes {
179                    description,
180                    file_metadata,
181                    schema,
182                    sync_enabled,
183                    tags,
184                    additional_properties,
185                    _unparsed,
186                };
187
188                Ok(content)
189            }
190        }
191
192        deserializer.deserialize_any(PatchTableRequestDataAttributesVisitor)
193    }
194}