datadog_api_client/datadogV2/model/
model_custom_framework_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/// Framework Data Attributes.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CustomFrameworkDataAttributes {
14    /// Framework Description
15    #[serde(rename = "description")]
16    pub description: Option<String>,
17    /// Framework Handle
18    #[serde(rename = "handle")]
19    pub handle: String,
20    /// Framework Icon URL
21    #[serde(rename = "icon_url")]
22    pub icon_url: Option<String>,
23    /// Framework Name
24    #[serde(rename = "name")]
25    pub name: String,
26    /// Framework Requirements
27    #[serde(rename = "requirements")]
28    pub requirements: Vec<crate::datadogV2::model::CustomFrameworkRequirement>,
29    /// Framework Version
30    #[serde(rename = "version")]
31    pub version: String,
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 CustomFrameworkDataAttributes {
40    pub fn new(
41        handle: String,
42        name: String,
43        requirements: Vec<crate::datadogV2::model::CustomFrameworkRequirement>,
44        version: String,
45    ) -> CustomFrameworkDataAttributes {
46        CustomFrameworkDataAttributes {
47            description: None,
48            handle,
49            icon_url: None,
50            name,
51            requirements,
52            version,
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 icon_url(mut self, value: String) -> Self {
64        self.icon_url = Some(value);
65        self
66    }
67
68    pub fn additional_properties(
69        mut self,
70        value: std::collections::BTreeMap<String, serde_json::Value>,
71    ) -> Self {
72        self.additional_properties = value;
73        self
74    }
75}
76
77impl<'de> Deserialize<'de> for CustomFrameworkDataAttributes {
78    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
79    where
80        D: Deserializer<'de>,
81    {
82        struct CustomFrameworkDataAttributesVisitor;
83        impl<'a> Visitor<'a> for CustomFrameworkDataAttributesVisitor {
84            type Value = CustomFrameworkDataAttributes;
85
86            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
87                f.write_str("a mapping")
88            }
89
90            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
91            where
92                M: MapAccess<'a>,
93            {
94                let mut description: Option<String> = None;
95                let mut handle: Option<String> = None;
96                let mut icon_url: Option<String> = None;
97                let mut name: Option<String> = None;
98                let mut requirements: Option<
99                    Vec<crate::datadogV2::model::CustomFrameworkRequirement>,
100                > = None;
101                let mut version: 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                        "description" => {
111                            if v.is_null() {
112                                continue;
113                            }
114                            description =
115                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
116                        }
117                        "handle" => {
118                            handle = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
119                        }
120                        "icon_url" => {
121                            if v.is_null() {
122                                continue;
123                            }
124                            icon_url = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
125                        }
126                        "name" => {
127                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
128                        }
129                        "requirements" => {
130                            requirements =
131                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
132                        }
133                        "version" => {
134                            version = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
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 handle = handle.ok_or_else(|| M::Error::missing_field("handle"))?;
144                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
145                let requirements =
146                    requirements.ok_or_else(|| M::Error::missing_field("requirements"))?;
147                let version = version.ok_or_else(|| M::Error::missing_field("version"))?;
148
149                let content = CustomFrameworkDataAttributes {
150                    description,
151                    handle,
152                    icon_url,
153                    name,
154                    requirements,
155                    version,
156                    additional_properties,
157                    _unparsed,
158                };
159
160                Ok(content)
161            }
162        }
163
164        deserializer.deserialize_any(CustomFrameworkDataAttributesVisitor)
165    }
166}