datadog_api_client/datadogV2/model/
model_create_open_api_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/// Data envelope for `CreateOpenAPIResponse`.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CreateOpenAPIResponseData {
14    /// Attributes for `CreateOpenAPI`.
15    #[serde(rename = "attributes")]
16    pub attributes: Option<crate::datadogV2::model::CreateOpenAPIResponseAttributes>,
17    /// API identifier.
18    #[serde(rename = "id")]
19    pub id: Option<uuid::Uuid>,
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 CreateOpenAPIResponseData {
28    pub fn new() -> CreateOpenAPIResponseData {
29        CreateOpenAPIResponseData {
30            attributes: None,
31            id: None,
32            additional_properties: std::collections::BTreeMap::new(),
33            _unparsed: false,
34        }
35    }
36
37    pub fn attributes(
38        mut self,
39        value: crate::datadogV2::model::CreateOpenAPIResponseAttributes,
40    ) -> Self {
41        self.attributes = Some(value);
42        self
43    }
44
45    pub fn id(mut self, value: uuid::Uuid) -> Self {
46        self.id = 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 CreateOpenAPIResponseData {
60    fn default() -> Self {
61        Self::new()
62    }
63}
64
65impl<'de> Deserialize<'de> for CreateOpenAPIResponseData {
66    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67    where
68        D: Deserializer<'de>,
69    {
70        struct CreateOpenAPIResponseDataVisitor;
71        impl<'a> Visitor<'a> for CreateOpenAPIResponseDataVisitor {
72            type Value = CreateOpenAPIResponseData;
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::CreateOpenAPIResponseAttributes,
84                > = None;
85                let mut id: Option<uuid::Uuid> = None;
86                let mut additional_properties: std::collections::BTreeMap<
87                    String,
88                    serde_json::Value,
89                > = std::collections::BTreeMap::new();
90                let mut _unparsed = false;
91
92                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
93                    match k.as_str() {
94                        "attributes" => {
95                            if v.is_null() {
96                                continue;
97                            }
98                            attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
99                        }
100                        "id" => {
101                            if v.is_null() {
102                                continue;
103                            }
104                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
105                        }
106                        &_ => {
107                            if let Ok(value) = serde_json::from_value(v.clone()) {
108                                additional_properties.insert(k, value);
109                            }
110                        }
111                    }
112                }
113
114                let content = CreateOpenAPIResponseData {
115                    attributes,
116                    id,
117                    additional_properties,
118                    _unparsed,
119                };
120
121                Ok(content)
122            }
123        }
124
125        deserializer.deserialize_any(CreateOpenAPIResponseDataVisitor)
126    }
127}