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