datadog_api_client/datadogV2/model/
model_dataset_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/// **Datasets Object Constraints**
10/// - **Tag Limit per Dataset**:
11///   - Each restricted dataset supports a maximum of 10 key:value pairs per product.
12///
13/// - **Tag Key Rules per Telemetry Type**:
14///   - Only one tag key or attribute may be used to define access within a single telemetry type.
15///   - The same or different tag key may be used across different telemetry types.
16///
17/// - **Tag Value Uniqueness**:
18///   - Tag values must be unique within a single dataset.
19///   - A tag value used in one dataset cannot be reused in another dataset of the same telemetry type.
20#[non_exhaustive]
21#[skip_serializing_none]
22#[derive(Clone, Debug, PartialEq, Serialize)]
23pub struct DatasetResponse {
24    /// Dataset metadata and configuration(s).
25    #[serde(rename = "attributes")]
26    pub attributes: Option<crate::datadogV2::model::DatasetAttributesResponse>,
27    /// Unique identifier for the dataset.
28    #[serde(rename = "id")]
29    pub id: Option<String>,
30    /// Resource type, always "dataset".
31    #[serde(rename = "type")]
32    pub type_: Option<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 DatasetResponse {
41    pub fn new() -> DatasetResponse {
42        DatasetResponse {
43            attributes: None,
44            id: None,
45            type_: None,
46            additional_properties: std::collections::BTreeMap::new(),
47            _unparsed: false,
48        }
49    }
50
51    pub fn attributes(mut self, value: crate::datadogV2::model::DatasetAttributesResponse) -> Self {
52        self.attributes = Some(value);
53        self
54    }
55
56    pub fn id(mut self, value: String) -> Self {
57        self.id = Some(value);
58        self
59    }
60
61    pub fn type_(mut self, value: String) -> Self {
62        self.type_ = Some(value);
63        self
64    }
65
66    pub fn additional_properties(
67        mut self,
68        value: std::collections::BTreeMap<String, serde_json::Value>,
69    ) -> Self {
70        self.additional_properties = value;
71        self
72    }
73}
74
75impl Default for DatasetResponse {
76    fn default() -> Self {
77        Self::new()
78    }
79}
80
81impl<'de> Deserialize<'de> for DatasetResponse {
82    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
83    where
84        D: Deserializer<'de>,
85    {
86        struct DatasetResponseVisitor;
87        impl<'a> Visitor<'a> for DatasetResponseVisitor {
88            type Value = DatasetResponse;
89
90            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
91                f.write_str("a mapping")
92            }
93
94            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
95            where
96                M: MapAccess<'a>,
97            {
98                let mut attributes: Option<crate::datadogV2::model::DatasetAttributesResponse> =
99                    None;
100                let mut id: Option<String> = None;
101                let mut type_: Option<String> = None;
102                let mut additional_properties: std::collections::BTreeMap<
103                    String,
104                    serde_json::Value,
105                > = std::collections::BTreeMap::new();
106                let mut _unparsed = false;
107
108                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
109                    match k.as_str() {
110                        "attributes" => {
111                            if v.is_null() {
112                                continue;
113                            }
114                            attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
115                        }
116                        "id" => {
117                            if v.is_null() {
118                                continue;
119                            }
120                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
121                        }
122                        "type" => {
123                            if v.is_null() {
124                                continue;
125                            }
126                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
127                        }
128                        &_ => {
129                            if let Ok(value) = serde_json::from_value(v.clone()) {
130                                additional_properties.insert(k, value);
131                            }
132                        }
133                    }
134                }
135
136                let content = DatasetResponse {
137                    attributes,
138                    id,
139                    type_,
140                    additional_properties,
141                    _unparsed,
142                };
143
144                Ok(content)
145            }
146        }
147
148        deserializer.deserialize_any(DatasetResponseVisitor)
149    }
150}