datadog_api_client/datadogV2/model/
model_update_open_api_response_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/// Attributes for `UpdateOpenAPI`.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct UpdateOpenAPIResponseAttributes {
14    /// List of endpoints which couldn't be parsed.
15    #[serde(rename = "failed_endpoints")]
16    pub failed_endpoints: Option<Vec<crate::datadogV2::model::OpenAPIEndpoint>>,
17    #[serde(flatten)]
18    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
19    #[serde(skip)]
20    #[serde(default)]
21    pub(crate) _unparsed: bool,
22}
23
24impl UpdateOpenAPIResponseAttributes {
25    pub fn new() -> UpdateOpenAPIResponseAttributes {
26        UpdateOpenAPIResponseAttributes {
27            failed_endpoints: None,
28            additional_properties: std::collections::BTreeMap::new(),
29            _unparsed: false,
30        }
31    }
32
33    pub fn failed_endpoints(
34        mut self,
35        value: Vec<crate::datadogV2::model::OpenAPIEndpoint>,
36    ) -> Self {
37        self.failed_endpoints = Some(value);
38        self
39    }
40
41    pub fn additional_properties(
42        mut self,
43        value: std::collections::BTreeMap<String, serde_json::Value>,
44    ) -> Self {
45        self.additional_properties = value;
46        self
47    }
48}
49
50impl Default for UpdateOpenAPIResponseAttributes {
51    fn default() -> Self {
52        Self::new()
53    }
54}
55
56impl<'de> Deserialize<'de> for UpdateOpenAPIResponseAttributes {
57    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
58    where
59        D: Deserializer<'de>,
60    {
61        struct UpdateOpenAPIResponseAttributesVisitor;
62        impl<'a> Visitor<'a> for UpdateOpenAPIResponseAttributesVisitor {
63            type Value = UpdateOpenAPIResponseAttributes;
64
65            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
66                f.write_str("a mapping")
67            }
68
69            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
70            where
71                M: MapAccess<'a>,
72            {
73                let mut failed_endpoints: Option<Vec<crate::datadogV2::model::OpenAPIEndpoint>> =
74                    None;
75                let mut additional_properties: std::collections::BTreeMap<
76                    String,
77                    serde_json::Value,
78                > = std::collections::BTreeMap::new();
79                let mut _unparsed = false;
80
81                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
82                    match k.as_str() {
83                        "failed_endpoints" => {
84                            if v.is_null() {
85                                continue;
86                            }
87                            failed_endpoints =
88                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
89                        }
90                        &_ => {
91                            if let Ok(value) = serde_json::from_value(v.clone()) {
92                                additional_properties.insert(k, value);
93                            }
94                        }
95                    }
96                }
97
98                let content = UpdateOpenAPIResponseAttributes {
99                    failed_endpoints,
100                    additional_properties,
101                    _unparsed,
102                };
103
104                Ok(content)
105            }
106        }
107
108        deserializer.deserialize_any(UpdateOpenAPIResponseAttributesVisitor)
109    }
110}