datadog_api_client/datadogV2/model/
model_freshservice_integration.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct FreshserviceIntegration {
14 #[serde(rename = "credentials")]
16 pub credentials: crate::datadogV2::model::FreshserviceCredentials,
17 #[serde(rename = "type")]
19 pub type_: crate::datadogV2::model::FreshserviceIntegrationType,
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 FreshserviceIntegration {
28 pub fn new(
29 credentials: crate::datadogV2::model::FreshserviceCredentials,
30 type_: crate::datadogV2::model::FreshserviceIntegrationType,
31 ) -> FreshserviceIntegration {
32 FreshserviceIntegration {
33 credentials,
34 type_,
35 additional_properties: std::collections::BTreeMap::new(),
36 _unparsed: false,
37 }
38 }
39
40 pub fn additional_properties(
41 mut self,
42 value: std::collections::BTreeMap<String, serde_json::Value>,
43 ) -> Self {
44 self.additional_properties = value;
45 self
46 }
47}
48
49impl<'de> Deserialize<'de> for FreshserviceIntegration {
50 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
51 where
52 D: Deserializer<'de>,
53 {
54 struct FreshserviceIntegrationVisitor;
55 impl<'a> Visitor<'a> for FreshserviceIntegrationVisitor {
56 type Value = FreshserviceIntegration;
57
58 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
59 f.write_str("a mapping")
60 }
61
62 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
63 where
64 M: MapAccess<'a>,
65 {
66 let mut credentials: Option<crate::datadogV2::model::FreshserviceCredentials> =
67 None;
68 let mut type_: Option<crate::datadogV2::model::FreshserviceIntegrationType> = None;
69 let mut additional_properties: std::collections::BTreeMap<
70 String,
71 serde_json::Value,
72 > = std::collections::BTreeMap::new();
73 let mut _unparsed = false;
74
75 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
76 match k.as_str() {
77 "credentials" => {
78 credentials =
79 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
80 if let Some(ref _credentials) = credentials {
81 match _credentials {
82 crate::datadogV2::model::FreshserviceCredentials::UnparsedObject(_credentials) => {
83 _unparsed = true;
84 },
85 _ => {}
86 }
87 }
88 }
89 "type" => {
90 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
91 if let Some(ref _type_) = type_ {
92 match _type_ {
93 crate::datadogV2::model::FreshserviceIntegrationType::UnparsedObject(_type_) => {
94 _unparsed = true;
95 },
96 _ => {}
97 }
98 }
99 }
100 &_ => {
101 if let Ok(value) = serde_json::from_value(v.clone()) {
102 additional_properties.insert(k, value);
103 }
104 }
105 }
106 }
107 let credentials =
108 credentials.ok_or_else(|| M::Error::missing_field("credentials"))?;
109 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
110
111 let content = FreshserviceIntegration {
112 credentials,
113 type_,
114 additional_properties,
115 _unparsed,
116 };
117
118 Ok(content)
119 }
120 }
121
122 deserializer.deserialize_any(FreshserviceIntegrationVisitor)
123 }
124}