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