datadog_api_client/datadogV2/model/
model_custom_attribute_config_resource_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/// Custom attribute resource attributes
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CustomAttributeConfigResourceAttributes {
14    /// Custom attribute config identifier.
15    #[serde(rename = "case_type_id")]
16    pub case_type_id: String,
17    /// Custom attribute description.
18    #[serde(rename = "description")]
19    pub description: Option<String>,
20    /// Custom attribute name.
21    #[serde(rename = "display_name")]
22    pub display_name: String,
23    /// Whether multiple values can be set
24    #[serde(rename = "is_multi")]
25    pub is_multi: bool,
26    /// Custom attribute key. This will be the value use to search on this custom attribute
27    #[serde(rename = "key")]
28    pub key: String,
29    /// Custom attributes type
30    #[serde(rename = "type")]
31    pub type_: crate::datadogV2::model::CustomAttributeType,
32    #[serde(flatten)]
33    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
34    #[serde(skip)]
35    #[serde(default)]
36    pub(crate) _unparsed: bool,
37}
38
39impl CustomAttributeConfigResourceAttributes {
40    pub fn new(
41        case_type_id: String,
42        display_name: String,
43        is_multi: bool,
44        key: String,
45        type_: crate::datadogV2::model::CustomAttributeType,
46    ) -> CustomAttributeConfigResourceAttributes {
47        CustomAttributeConfigResourceAttributes {
48            case_type_id,
49            description: None,
50            display_name,
51            is_multi,
52            key,
53            type_,
54            additional_properties: std::collections::BTreeMap::new(),
55            _unparsed: false,
56        }
57    }
58
59    pub fn description(mut self, value: String) -> Self {
60        self.description = Some(value);
61        self
62    }
63
64    pub fn additional_properties(
65        mut self,
66        value: std::collections::BTreeMap<String, serde_json::Value>,
67    ) -> Self {
68        self.additional_properties = value;
69        self
70    }
71}
72
73impl<'de> Deserialize<'de> for CustomAttributeConfigResourceAttributes {
74    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
75    where
76        D: Deserializer<'de>,
77    {
78        struct CustomAttributeConfigResourceAttributesVisitor;
79        impl<'a> Visitor<'a> for CustomAttributeConfigResourceAttributesVisitor {
80            type Value = CustomAttributeConfigResourceAttributes;
81
82            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
83                f.write_str("a mapping")
84            }
85
86            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
87            where
88                M: MapAccess<'a>,
89            {
90                let mut case_type_id: Option<String> = None;
91                let mut description: Option<String> = None;
92                let mut display_name: Option<String> = None;
93                let mut is_multi: Option<bool> = None;
94                let mut key: Option<String> = None;
95                let mut type_: Option<crate::datadogV2::model::CustomAttributeType> = None;
96                let mut additional_properties: std::collections::BTreeMap<
97                    String,
98                    serde_json::Value,
99                > = std::collections::BTreeMap::new();
100                let mut _unparsed = false;
101
102                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
103                    match k.as_str() {
104                        "case_type_id" => {
105                            case_type_id =
106                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
107                        }
108                        "description" => {
109                            if v.is_null() {
110                                continue;
111                            }
112                            description =
113                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114                        }
115                        "display_name" => {
116                            display_name =
117                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
118                        }
119                        "is_multi" => {
120                            is_multi = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
121                        }
122                        "key" => {
123                            key = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
124                        }
125                        "type" => {
126                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
127                            if let Some(ref _type_) = type_ {
128                                match _type_ {
129                                    crate::datadogV2::model::CustomAttributeType::UnparsedObject(_type_) => {
130                                        _unparsed = true;
131                                    },
132                                    _ => {}
133                                }
134                            }
135                        }
136                        &_ => {
137                            if let Ok(value) = serde_json::from_value(v.clone()) {
138                                additional_properties.insert(k, value);
139                            }
140                        }
141                    }
142                }
143                let case_type_id =
144                    case_type_id.ok_or_else(|| M::Error::missing_field("case_type_id"))?;
145                let display_name =
146                    display_name.ok_or_else(|| M::Error::missing_field("display_name"))?;
147                let is_multi = is_multi.ok_or_else(|| M::Error::missing_field("is_multi"))?;
148                let key = key.ok_or_else(|| M::Error::missing_field("key"))?;
149                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
150
151                let content = CustomAttributeConfigResourceAttributes {
152                    case_type_id,
153                    description,
154                    display_name,
155                    is_multi,
156                    key,
157                    type_,
158                    additional_properties,
159                    _unparsed,
160                };
161
162                Ok(content)
163            }
164        }
165
166        deserializer.deserialize_any(CustomAttributeConfigResourceAttributesVisitor)
167    }
168}