datadog_api_client/datadogV2/model/
model_entity_v3_datadog_integration_opsgenie.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 EntityV3DatadogIntegrationOpsgenie {
14 #[serde(rename = "region")]
16 pub region: Option<String>,
17 #[serde(rename = "serviceURL")]
19 pub service_url: String,
20 #[serde(skip)]
21 #[serde(default)]
22 pub(crate) _unparsed: bool,
23}
24
25impl EntityV3DatadogIntegrationOpsgenie {
26 pub fn new(service_url: String) -> EntityV3DatadogIntegrationOpsgenie {
27 EntityV3DatadogIntegrationOpsgenie {
28 region: None,
29 service_url,
30 _unparsed: false,
31 }
32 }
33
34 pub fn region(mut self, value: String) -> Self {
35 self.region = Some(value);
36 self
37 }
38}
39
40impl<'de> Deserialize<'de> for EntityV3DatadogIntegrationOpsgenie {
41 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
42 where
43 D: Deserializer<'de>,
44 {
45 struct EntityV3DatadogIntegrationOpsgenieVisitor;
46 impl<'a> Visitor<'a> for EntityV3DatadogIntegrationOpsgenieVisitor {
47 type Value = EntityV3DatadogIntegrationOpsgenie;
48
49 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
50 f.write_str("a mapping")
51 }
52
53 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
54 where
55 M: MapAccess<'a>,
56 {
57 let mut region: Option<String> = None;
58 let mut service_url: Option<String> = None;
59 let mut _unparsed = false;
60
61 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
62 match k.as_str() {
63 "region" => {
64 if v.is_null() {
65 continue;
66 }
67 region = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
68 }
69 "serviceURL" => {
70 service_url =
71 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
72 }
73 &_ => {
74 return Err(serde::de::Error::custom(
75 "Additional properties not allowed",
76 ));
77 }
78 }
79 }
80 let service_url =
81 service_url.ok_or_else(|| M::Error::missing_field("service_url"))?;
82
83 let content = EntityV3DatadogIntegrationOpsgenie {
84 region,
85 service_url,
86 _unparsed,
87 };
88
89 Ok(content)
90 }
91 }
92
93 deserializer.deserialize_any(EntityV3DatadogIntegrationOpsgenieVisitor)
94 }
95}