datadog_api_client/datadogV2/model/
model_component_properties.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/// Properties of a UI component. Different component types can have their own additional unique properties. See the [components documentation](<https://docs.datadoghq.com/service_management/app_builder/components/>) for more detail on each component type and its properties.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ComponentProperties {
14    /// The child components of the UI component.
15    #[serde(rename = "children")]
16    pub children: Option<Vec<crate::datadogV2::model::Component>>,
17    /// Whether the UI component is visible. If this is a string, it must be a valid JavaScript expression that evaluates to a boolean.
18    #[serde(rename = "isVisible")]
19    pub is_visible: Option<crate::datadogV2::model::ComponentPropertiesIsVisible>,
20    #[serde(flatten)]
21    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22    #[serde(skip)]
23    #[serde(default)]
24    pub(crate) _unparsed: bool,
25}
26
27impl ComponentProperties {
28    pub fn new() -> ComponentProperties {
29        ComponentProperties {
30            children: None,
31            is_visible: None,
32            additional_properties: std::collections::BTreeMap::new(),
33            _unparsed: false,
34        }
35    }
36
37    pub fn children(mut self, value: Vec<crate::datadogV2::model::Component>) -> Self {
38        self.children = Some(value);
39        self
40    }
41
42    pub fn is_visible(
43        mut self,
44        value: crate::datadogV2::model::ComponentPropertiesIsVisible,
45    ) -> Self {
46        self.is_visible = Some(value);
47        self
48    }
49
50    pub fn additional_properties(
51        mut self,
52        value: std::collections::BTreeMap<String, serde_json::Value>,
53    ) -> Self {
54        self.additional_properties = value;
55        self
56    }
57}
58
59impl Default for ComponentProperties {
60    fn default() -> Self {
61        Self::new()
62    }
63}
64
65impl<'de> Deserialize<'de> for ComponentProperties {
66    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67    where
68        D: Deserializer<'de>,
69    {
70        struct ComponentPropertiesVisitor;
71        impl<'a> Visitor<'a> for ComponentPropertiesVisitor {
72            type Value = ComponentProperties;
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 children: Option<Vec<crate::datadogV2::model::Component>> = None;
83                let mut is_visible: Option<crate::datadogV2::model::ComponentPropertiesIsVisible> =
84                    None;
85                let mut additional_properties: std::collections::BTreeMap<
86                    String,
87                    serde_json::Value,
88                > = std::collections::BTreeMap::new();
89                let mut _unparsed = false;
90
91                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
92                    match k.as_str() {
93                        "children" => {
94                            if v.is_null() {
95                                continue;
96                            }
97                            children = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
98                        }
99                        "isVisible" => {
100                            if v.is_null() {
101                                continue;
102                            }
103                            is_visible = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
104                            if let Some(ref _is_visible) = is_visible {
105                                match _is_visible {
106                                    crate::datadogV2::model::ComponentPropertiesIsVisible::UnparsedObject(_is_visible) => {
107                                        _unparsed = true;
108                                    },
109                                    _ => {}
110                                }
111                            }
112                        }
113                        &_ => {
114                            if let Ok(value) = serde_json::from_value(v.clone()) {
115                                additional_properties.insert(k, value);
116                            }
117                        }
118                    }
119                }
120
121                let content = ComponentProperties {
122                    children,
123                    is_visible,
124                    additional_properties,
125                    _unparsed,
126                };
127
128                Ok(content)
129            }
130        }
131
132        deserializer.deserialize_any(ComponentPropertiesVisitor)
133    }
134}