Skip to main content

nominal_api/conjure/objects/scout/integrations/api/
update_integration_details.rs

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