Skip to main content

nominal_api/conjure/objects/secrets/api/
search_secrets_query.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 SearchSecretsQuery {
7    SearchText(String),
8    Label(super::super::super::api::Label),
9    Property(super::super::super::api::Property),
10    And(std::collections::BTreeSet<super::SearchSecretsQuery>),
11    Or(std::collections::BTreeSet<super::SearchSecretsQuery>),
12    Workspace(super::super::super::api::rids::WorkspaceRid),
13    /// An unknown variant.
14    Unknown(Unknown),
15}
16impl ser::Serialize for SearchSecretsQuery {
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            SearchSecretsQuery::SearchText(value) => {
24                map.serialize_entry(&"type", &"searchText")?;
25                map.serialize_entry(&"searchText", value)?;
26            }
27            SearchSecretsQuery::Label(value) => {
28                map.serialize_entry(&"type", &"label")?;
29                map.serialize_entry(&"label", value)?;
30            }
31            SearchSecretsQuery::Property(value) => {
32                map.serialize_entry(&"type", &"property")?;
33                map.serialize_entry(&"property", value)?;
34            }
35            SearchSecretsQuery::And(value) => {
36                map.serialize_entry(&"type", &"and")?;
37                map.serialize_entry(&"and", value)?;
38            }
39            SearchSecretsQuery::Or(value) => {
40                map.serialize_entry(&"type", &"or")?;
41                map.serialize_entry(&"or", value)?;
42            }
43            SearchSecretsQuery::Workspace(value) => {
44                map.serialize_entry(&"type", &"workspace")?;
45                map.serialize_entry(&"workspace", value)?;
46            }
47            SearchSecretsQuery::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 SearchSecretsQuery {
56    fn deserialize<D>(d: D) -> Result<SearchSecretsQuery, 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 = SearchSecretsQuery;
66    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
67        fmt.write_str("union SearchSecretsQuery")
68    }
69    fn visit_map<A>(self, mut map: A) -> Result<SearchSecretsQuery, 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                    (Variant_::SearchText, Some(Variant_::SearchText)) => {
79                        let value = map.next_value()?;
80                        SearchSecretsQuery::SearchText(value)
81                    }
82                    (Variant_::Label, Some(Variant_::Label)) => {
83                        let value = map.next_value()?;
84                        SearchSecretsQuery::Label(value)
85                    }
86                    (Variant_::Property, Some(Variant_::Property)) => {
87                        let value = map.next_value()?;
88                        SearchSecretsQuery::Property(value)
89                    }
90                    (Variant_::And, Some(Variant_::And)) => {
91                        let value = map.next_value()?;
92                        SearchSecretsQuery::And(value)
93                    }
94                    (Variant_::Or, Some(Variant_::Or)) => {
95                        let value = map.next_value()?;
96                        SearchSecretsQuery::Or(value)
97                    }
98                    (Variant_::Workspace, Some(Variant_::Workspace)) => {
99                        let value = map.next_value()?;
100                        SearchSecretsQuery::Workspace(value)
101                    }
102                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
103                        if type_ == b {
104                            let value = map.next_value()?;
105                            SearchSecretsQuery::Unknown(Unknown { type_, value })
106                        } else {
107                            return Err(
108                                de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
109                            )
110                        }
111                    }
112                    (variant, Some(key)) => {
113                        return Err(
114                            de::Error::invalid_value(
115                                de::Unexpected::Str(key.as_str()),
116                                &variant.as_str(),
117                            ),
118                        );
119                    }
120                    (variant, None) => {
121                        return Err(de::Error::missing_field(variant.as_str()));
122                    }
123                }
124            }
125            Some(UnionField_::Value(variant)) => {
126                let value = match &variant {
127                    Variant_::SearchText => {
128                        let value = map.next_value()?;
129                        SearchSecretsQuery::SearchText(value)
130                    }
131                    Variant_::Label => {
132                        let value = map.next_value()?;
133                        SearchSecretsQuery::Label(value)
134                    }
135                    Variant_::Property => {
136                        let value = map.next_value()?;
137                        SearchSecretsQuery::Property(value)
138                    }
139                    Variant_::And => {
140                        let value = map.next_value()?;
141                        SearchSecretsQuery::And(value)
142                    }
143                    Variant_::Or => {
144                        let value = map.next_value()?;
145                        SearchSecretsQuery::Or(value)
146                    }
147                    Variant_::Workspace => {
148                        let value = map.next_value()?;
149                        SearchSecretsQuery::Workspace(value)
150                    }
151                    Variant_::Unknown(type_) => {
152                        let value = map.next_value()?;
153                        SearchSecretsQuery::Unknown(Unknown {
154                            type_: type_.clone(),
155                            value,
156                        })
157                    }
158                };
159                if map.next_key::<UnionTypeField_>()?.is_none() {
160                    return Err(de::Error::missing_field("type"));
161                }
162                let type_variant = map.next_value::<Variant_>()?;
163                if variant != type_variant {
164                    return Err(
165                        de::Error::invalid_value(
166                            de::Unexpected::Str(type_variant.as_str()),
167                            &variant.as_str(),
168                        ),
169                    );
170                }
171                value
172            }
173            None => return Err(de::Error::missing_field("type")),
174        };
175        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
176            return Err(de::Error::invalid_length(3, &"type and value fields"));
177        }
178        Ok(v)
179    }
180}
181#[derive(PartialEq)]
182enum Variant_ {
183    SearchText,
184    Label,
185    Property,
186    And,
187    Or,
188    Workspace,
189    Unknown(Box<str>),
190}
191impl Variant_ {
192    fn as_str(&self) -> &'static str {
193        match *self {
194            Variant_::SearchText => "searchText",
195            Variant_::Label => "label",
196            Variant_::Property => "property",
197            Variant_::And => "and",
198            Variant_::Or => "or",
199            Variant_::Workspace => "workspace",
200            Variant_::Unknown(_) => "unknown variant",
201        }
202    }
203}
204impl<'de> de::Deserialize<'de> for Variant_ {
205    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
206    where
207        D: de::Deserializer<'de>,
208    {
209        d.deserialize_str(VariantVisitor_)
210    }
211}
212struct VariantVisitor_;
213impl<'de> de::Visitor<'de> for VariantVisitor_ {
214    type Value = Variant_;
215    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
216        fmt.write_str("string")
217    }
218    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
219    where
220        E: de::Error,
221    {
222        let v = match value {
223            "searchText" => Variant_::SearchText,
224            "label" => Variant_::Label,
225            "property" => Variant_::Property,
226            "and" => Variant_::And,
227            "or" => Variant_::Or,
228            "workspace" => Variant_::Workspace,
229            value => Variant_::Unknown(value.to_string().into_boxed_str()),
230        };
231        Ok(v)
232    }
233}
234///An unknown variant of the SearchSecretsQuery union.
235#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
236pub struct Unknown {
237    type_: Box<str>,
238    value: conjure_object::Any,
239}
240impl Unknown {
241    /// Returns the unknown variant's type name.
242    #[inline]
243    pub fn type_(&self) -> &str {
244        &self.type_
245    }
246}