nominal_api/conjure/objects/scout/integrations/api/
integration_details.rs1use conjure_object::serde::{ser, de};
2use conjure_object::serde::ser::SerializeMap as SerializeMap_;
3use conjure_object::private::{UnionField_, UnionTypeField_};
4use std::fmt;
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub enum IntegrationDetails {
7 SlackWebhookIntegration(super::SlackWebhookIntegration),
8 OpsgenieIntegration(super::OpsgenieIntegration),
9 SimpleWebhookIntegration(super::SimpleWebhookIntegration),
10 SecureWebhookIntegration(super::SecureWebhookIntegration),
11 TeamsWebhookIntegration(super::TeamsWebhookIntegration),
12 PagerDutyIntegration(super::PagerDutyIntegration),
13 Unknown(Unknown),
15}
16impl ser::Serialize for IntegrationDetails {
17 fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
18 where
19 S: ser::Serializer,
20 {
21 let mut map = s.serialize_map(Some(2))?;
22 match self {
23 IntegrationDetails::SlackWebhookIntegration(value) => {
24 map.serialize_entry(&"type", &"slackWebhookIntegration")?;
25 map.serialize_entry(&"slackWebhookIntegration", value)?;
26 }
27 IntegrationDetails::OpsgenieIntegration(value) => {
28 map.serialize_entry(&"type", &"opsgenieIntegration")?;
29 map.serialize_entry(&"opsgenieIntegration", value)?;
30 }
31 IntegrationDetails::SimpleWebhookIntegration(value) => {
32 map.serialize_entry(&"type", &"simpleWebhookIntegration")?;
33 map.serialize_entry(&"simpleWebhookIntegration", value)?;
34 }
35 IntegrationDetails::SecureWebhookIntegration(value) => {
36 map.serialize_entry(&"type", &"secureWebhookIntegration")?;
37 map.serialize_entry(&"secureWebhookIntegration", value)?;
38 }
39 IntegrationDetails::TeamsWebhookIntegration(value) => {
40 map.serialize_entry(&"type", &"teamsWebhookIntegration")?;
41 map.serialize_entry(&"teamsWebhookIntegration", value)?;
42 }
43 IntegrationDetails::PagerDutyIntegration(value) => {
44 map.serialize_entry(&"type", &"pagerDutyIntegration")?;
45 map.serialize_entry(&"pagerDutyIntegration", value)?;
46 }
47 IntegrationDetails::Unknown(value) => {
48 map.serialize_entry(&"type", &value.type_)?;
49 map.serialize_entry(&value.type_, &value.value)?;
50 }
51 }
52 map.end()
53 }
54}
55impl<'de> de::Deserialize<'de> for IntegrationDetails {
56 fn deserialize<D>(d: D) -> Result<IntegrationDetails, D::Error>
57 where
58 D: de::Deserializer<'de>,
59 {
60 d.deserialize_map(Visitor_)
61 }
62}
63struct Visitor_;
64impl<'de> de::Visitor<'de> for Visitor_ {
65 type Value = IntegrationDetails;
66 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
67 fmt.write_str("union IntegrationDetails")
68 }
69 fn visit_map<A>(self, mut map: A) -> Result<IntegrationDetails, A::Error>
70 where
71 A: de::MapAccess<'de>,
72 {
73 let v = match map.next_key::<UnionField_<Variant_>>()? {
74 Some(UnionField_::Type) => {
75 let variant = map.next_value()?;
76 let key = map.next_key()?;
77 match (variant, key) {
78 (
79 Variant_::SlackWebhookIntegration,
80 Some(Variant_::SlackWebhookIntegration),
81 ) => {
82 let value = map.next_value()?;
83 IntegrationDetails::SlackWebhookIntegration(value)
84 }
85 (
86 Variant_::OpsgenieIntegration,
87 Some(Variant_::OpsgenieIntegration),
88 ) => {
89 let value = map.next_value()?;
90 IntegrationDetails::OpsgenieIntegration(value)
91 }
92 (
93 Variant_::SimpleWebhookIntegration,
94 Some(Variant_::SimpleWebhookIntegration),
95 ) => {
96 let value = map.next_value()?;
97 IntegrationDetails::SimpleWebhookIntegration(value)
98 }
99 (
100 Variant_::SecureWebhookIntegration,
101 Some(Variant_::SecureWebhookIntegration),
102 ) => {
103 let value = map.next_value()?;
104 IntegrationDetails::SecureWebhookIntegration(value)
105 }
106 (
107 Variant_::TeamsWebhookIntegration,
108 Some(Variant_::TeamsWebhookIntegration),
109 ) => {
110 let value = map.next_value()?;
111 IntegrationDetails::TeamsWebhookIntegration(value)
112 }
113 (
114 Variant_::PagerDutyIntegration,
115 Some(Variant_::PagerDutyIntegration),
116 ) => {
117 let value = map.next_value()?;
118 IntegrationDetails::PagerDutyIntegration(value)
119 }
120 (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
121 if type_ == b {
122 let value = map.next_value()?;
123 IntegrationDetails::Unknown(Unknown { type_, value })
124 } else {
125 return Err(
126 de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
127 )
128 }
129 }
130 (variant, Some(key)) => {
131 return Err(
132 de::Error::invalid_value(
133 de::Unexpected::Str(key.as_str()),
134 &variant.as_str(),
135 ),
136 );
137 }
138 (variant, None) => {
139 return Err(de::Error::missing_field(variant.as_str()));
140 }
141 }
142 }
143 Some(UnionField_::Value(variant)) => {
144 let value = match &variant {
145 Variant_::SlackWebhookIntegration => {
146 let value = map.next_value()?;
147 IntegrationDetails::SlackWebhookIntegration(value)
148 }
149 Variant_::OpsgenieIntegration => {
150 let value = map.next_value()?;
151 IntegrationDetails::OpsgenieIntegration(value)
152 }
153 Variant_::SimpleWebhookIntegration => {
154 let value = map.next_value()?;
155 IntegrationDetails::SimpleWebhookIntegration(value)
156 }
157 Variant_::SecureWebhookIntegration => {
158 let value = map.next_value()?;
159 IntegrationDetails::SecureWebhookIntegration(value)
160 }
161 Variant_::TeamsWebhookIntegration => {
162 let value = map.next_value()?;
163 IntegrationDetails::TeamsWebhookIntegration(value)
164 }
165 Variant_::PagerDutyIntegration => {
166 let value = map.next_value()?;
167 IntegrationDetails::PagerDutyIntegration(value)
168 }
169 Variant_::Unknown(type_) => {
170 let value = map.next_value()?;
171 IntegrationDetails::Unknown(Unknown {
172 type_: type_.clone(),
173 value,
174 })
175 }
176 };
177 if map.next_key::<UnionTypeField_>()?.is_none() {
178 return Err(de::Error::missing_field("type"));
179 }
180 let type_variant = map.next_value::<Variant_>()?;
181 if variant != type_variant {
182 return Err(
183 de::Error::invalid_value(
184 de::Unexpected::Str(type_variant.as_str()),
185 &variant.as_str(),
186 ),
187 );
188 }
189 value
190 }
191 None => return Err(de::Error::missing_field("type")),
192 };
193 if map.next_key::<UnionField_<Variant_>>()?.is_some() {
194 return Err(de::Error::invalid_length(3, &"type and value fields"));
195 }
196 Ok(v)
197 }
198}
199#[derive(PartialEq)]
200enum Variant_ {
201 SlackWebhookIntegration,
202 OpsgenieIntegration,
203 SimpleWebhookIntegration,
204 SecureWebhookIntegration,
205 TeamsWebhookIntegration,
206 PagerDutyIntegration,
207 Unknown(Box<str>),
208}
209impl Variant_ {
210 fn as_str(&self) -> &'static str {
211 match *self {
212 Variant_::SlackWebhookIntegration => "slackWebhookIntegration",
213 Variant_::OpsgenieIntegration => "opsgenieIntegration",
214 Variant_::SimpleWebhookIntegration => "simpleWebhookIntegration",
215 Variant_::SecureWebhookIntegration => "secureWebhookIntegration",
216 Variant_::TeamsWebhookIntegration => "teamsWebhookIntegration",
217 Variant_::PagerDutyIntegration => "pagerDutyIntegration",
218 Variant_::Unknown(_) => "unknown variant",
219 }
220 }
221}
222impl<'de> de::Deserialize<'de> for Variant_ {
223 fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
224 where
225 D: de::Deserializer<'de>,
226 {
227 d.deserialize_str(VariantVisitor_)
228 }
229}
230struct VariantVisitor_;
231impl<'de> de::Visitor<'de> for VariantVisitor_ {
232 type Value = Variant_;
233 fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
234 fmt.write_str("string")
235 }
236 fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
237 where
238 E: de::Error,
239 {
240 let v = match value {
241 "slackWebhookIntegration" => Variant_::SlackWebhookIntegration,
242 "opsgenieIntegration" => Variant_::OpsgenieIntegration,
243 "simpleWebhookIntegration" => Variant_::SimpleWebhookIntegration,
244 "secureWebhookIntegration" => Variant_::SecureWebhookIntegration,
245 "teamsWebhookIntegration" => Variant_::TeamsWebhookIntegration,
246 "pagerDutyIntegration" => Variant_::PagerDutyIntegration,
247 value => Variant_::Unknown(value.to_string().into_boxed_str()),
248 };
249 Ok(v)
250 }
251}
252#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
254pub struct Unknown {
255 type_: Box<str>,
256 value: conjure_object::Any,
257}
258impl Unknown {
259 #[inline]
261 pub fn type_(&self) -> &str {
262 &self.type_
263 }
264}