datadog_api_client/datadogV2/model/
model_rules_validate_query_request_data.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct RulesValidateQueryRequestData {
14 #[serde(rename = "attributes")]
16 pub attributes: Option<crate::datadogV2::model::RulesValidateQueryRequestDataAttributes>,
17 #[serde(rename = "id")]
19 pub id: Option<String>,
20 #[serde(rename = "type")]
22 pub type_: crate::datadogV2::model::RulesValidateQueryRequestDataType,
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 RulesValidateQueryRequestData {
31 pub fn new(
32 type_: crate::datadogV2::model::RulesValidateQueryRequestDataType,
33 ) -> RulesValidateQueryRequestData {
34 RulesValidateQueryRequestData {
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::RulesValidateQueryRequestDataAttributes,
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 RulesValidateQueryRequestData {
66 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67 where
68 D: Deserializer<'de>,
69 {
70 struct RulesValidateQueryRequestDataVisitor;
71 impl<'a> Visitor<'a> for RulesValidateQueryRequestDataVisitor {
72 type Value = RulesValidateQueryRequestData;
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::RulesValidateQueryRequestDataAttributes,
84 > = None;
85 let mut id: Option<String> = None;
86 let mut type_: Option<crate::datadogV2::model::RulesValidateQueryRequestDataType> =
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::RulesValidateQueryRequestDataType::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 = RulesValidateQueryRequestData {
129 attributes,
130 id,
131 type_,
132 additional_properties,
133 _unparsed,
134 };
135
136 Ok(content)
137 }
138 }
139
140 deserializer.deserialize_any(RulesValidateQueryRequestDataVisitor)
141 }
142}