Skip to main content

nominal_api/conjure/objects/scout/template/api/
search_templates_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 SearchTemplatesQuery {
7    And(Vec<super::SearchTemplatesQuery>),
8    Or(Vec<super::SearchTemplatesQuery>),
9    Not(Box<super::SearchTemplatesQuery>),
10    /// Performs case insensitive exact match search on the title.
11    ExactMatch(String),
12    /// Searches title and description only
13    SearchText(String),
14    #[deprecated(note = "use labels instead")]
15    Label(super::super::super::super::api::Label),
16    Labels(super::super::super::rids::api::LabelsFilter),
17    #[deprecated(note = "use properties")]
18    Property(super::super::super::super::api::Property),
19    Properties(super::super::super::rids::api::PropertiesFilter),
20    CreatedBy(super::super::super::rids::api::UserRid),
21    IsArchived(bool),
22    IsPublished(bool),
23    Workspace(super::super::super::super::api::rids::WorkspaceRid),
24    AuthorIsCurrentUser(bool),
25    AuthorRids(std::collections::BTreeSet<super::super::super::rids::api::UserRid>),
26    /// An unknown variant.
27    Unknown(Unknown),
28}
29impl ser::Serialize for SearchTemplatesQuery {
30    fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
31    where
32        S: ser::Serializer,
33    {
34        let mut map = s.serialize_map(Some(2))?;
35        match self {
36            SearchTemplatesQuery::And(value) => {
37                map.serialize_entry(&"type", &"and")?;
38                map.serialize_entry(&"and", value)?;
39            }
40            SearchTemplatesQuery::Or(value) => {
41                map.serialize_entry(&"type", &"or")?;
42                map.serialize_entry(&"or", value)?;
43            }
44            SearchTemplatesQuery::Not(value) => {
45                map.serialize_entry(&"type", &"not")?;
46                map.serialize_entry(&"not", value)?;
47            }
48            SearchTemplatesQuery::ExactMatch(value) => {
49                map.serialize_entry(&"type", &"exactMatch")?;
50                map.serialize_entry(&"exactMatch", value)?;
51            }
52            SearchTemplatesQuery::SearchText(value) => {
53                map.serialize_entry(&"type", &"searchText")?;
54                map.serialize_entry(&"searchText", value)?;
55            }
56            #[allow(deprecated)]
57            SearchTemplatesQuery::Label(value) => {
58                map.serialize_entry(&"type", &"label")?;
59                map.serialize_entry(&"label", value)?;
60            }
61            SearchTemplatesQuery::Labels(value) => {
62                map.serialize_entry(&"type", &"labels")?;
63                map.serialize_entry(&"labels", value)?;
64            }
65            #[allow(deprecated)]
66            SearchTemplatesQuery::Property(value) => {
67                map.serialize_entry(&"type", &"property")?;
68                map.serialize_entry(&"property", value)?;
69            }
70            SearchTemplatesQuery::Properties(value) => {
71                map.serialize_entry(&"type", &"properties")?;
72                map.serialize_entry(&"properties", value)?;
73            }
74            SearchTemplatesQuery::CreatedBy(value) => {
75                map.serialize_entry(&"type", &"createdBy")?;
76                map.serialize_entry(&"createdBy", value)?;
77            }
78            SearchTemplatesQuery::IsArchived(value) => {
79                map.serialize_entry(&"type", &"isArchived")?;
80                map.serialize_entry(&"isArchived", value)?;
81            }
82            SearchTemplatesQuery::IsPublished(value) => {
83                map.serialize_entry(&"type", &"isPublished")?;
84                map.serialize_entry(&"isPublished", value)?;
85            }
86            SearchTemplatesQuery::Workspace(value) => {
87                map.serialize_entry(&"type", &"workspace")?;
88                map.serialize_entry(&"workspace", value)?;
89            }
90            SearchTemplatesQuery::AuthorIsCurrentUser(value) => {
91                map.serialize_entry(&"type", &"authorIsCurrentUser")?;
92                map.serialize_entry(&"authorIsCurrentUser", value)?;
93            }
94            SearchTemplatesQuery::AuthorRids(value) => {
95                map.serialize_entry(&"type", &"authorRids")?;
96                map.serialize_entry(&"authorRids", value)?;
97            }
98            SearchTemplatesQuery::Unknown(value) => {
99                map.serialize_entry(&"type", &value.type_)?;
100                map.serialize_entry(&value.type_, &value.value)?;
101            }
102        }
103        map.end()
104    }
105}
106impl<'de> de::Deserialize<'de> for SearchTemplatesQuery {
107    fn deserialize<D>(d: D) -> Result<SearchTemplatesQuery, D::Error>
108    where
109        D: de::Deserializer<'de>,
110    {
111        d.deserialize_map(Visitor_)
112    }
113}
114struct Visitor_;
115impl<'de> de::Visitor<'de> for Visitor_ {
116    type Value = SearchTemplatesQuery;
117    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
118        fmt.write_str("union SearchTemplatesQuery")
119    }
120    fn visit_map<A>(self, mut map: A) -> Result<SearchTemplatesQuery, A::Error>
121    where
122        A: de::MapAccess<'de>,
123    {
124        let v = match map.next_key::<UnionField_<Variant_>>()? {
125            Some(UnionField_::Type) => {
126                let variant = map.next_value()?;
127                let key = map.next_key()?;
128                match (variant, key) {
129                    (Variant_::And, Some(Variant_::And)) => {
130                        let value = map.next_value()?;
131                        SearchTemplatesQuery::And(value)
132                    }
133                    (Variant_::Or, Some(Variant_::Or)) => {
134                        let value = map.next_value()?;
135                        SearchTemplatesQuery::Or(value)
136                    }
137                    (Variant_::Not, Some(Variant_::Not)) => {
138                        let value = map.next_value()?;
139                        SearchTemplatesQuery::Not(value)
140                    }
141                    (Variant_::ExactMatch, Some(Variant_::ExactMatch)) => {
142                        let value = map.next_value()?;
143                        SearchTemplatesQuery::ExactMatch(value)
144                    }
145                    (Variant_::SearchText, Some(Variant_::SearchText)) => {
146                        let value = map.next_value()?;
147                        SearchTemplatesQuery::SearchText(value)
148                    }
149                    #[allow(deprecated)]
150                    (Variant_::Label, Some(Variant_::Label)) => {
151                        let value = map.next_value()?;
152                        SearchTemplatesQuery::Label(value)
153                    }
154                    (Variant_::Labels, Some(Variant_::Labels)) => {
155                        let value = map.next_value()?;
156                        SearchTemplatesQuery::Labels(value)
157                    }
158                    #[allow(deprecated)]
159                    (Variant_::Property, Some(Variant_::Property)) => {
160                        let value = map.next_value()?;
161                        SearchTemplatesQuery::Property(value)
162                    }
163                    (Variant_::Properties, Some(Variant_::Properties)) => {
164                        let value = map.next_value()?;
165                        SearchTemplatesQuery::Properties(value)
166                    }
167                    (Variant_::CreatedBy, Some(Variant_::CreatedBy)) => {
168                        let value = map.next_value()?;
169                        SearchTemplatesQuery::CreatedBy(value)
170                    }
171                    (Variant_::IsArchived, Some(Variant_::IsArchived)) => {
172                        let value = map.next_value()?;
173                        SearchTemplatesQuery::IsArchived(value)
174                    }
175                    (Variant_::IsPublished, Some(Variant_::IsPublished)) => {
176                        let value = map.next_value()?;
177                        SearchTemplatesQuery::IsPublished(value)
178                    }
179                    (Variant_::Workspace, Some(Variant_::Workspace)) => {
180                        let value = map.next_value()?;
181                        SearchTemplatesQuery::Workspace(value)
182                    }
183                    (
184                        Variant_::AuthorIsCurrentUser,
185                        Some(Variant_::AuthorIsCurrentUser),
186                    ) => {
187                        let value = map.next_value()?;
188                        SearchTemplatesQuery::AuthorIsCurrentUser(value)
189                    }
190                    (Variant_::AuthorRids, Some(Variant_::AuthorRids)) => {
191                        let value = map.next_value()?;
192                        SearchTemplatesQuery::AuthorRids(value)
193                    }
194                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
195                        if type_ == b {
196                            let value = map.next_value()?;
197                            SearchTemplatesQuery::Unknown(Unknown { type_, value })
198                        } else {
199                            return Err(
200                                de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
201                            )
202                        }
203                    }
204                    (variant, Some(key)) => {
205                        return Err(
206                            de::Error::invalid_value(
207                                de::Unexpected::Str(key.as_str()),
208                                &variant.as_str(),
209                            ),
210                        );
211                    }
212                    (variant, None) => {
213                        return Err(de::Error::missing_field(variant.as_str()));
214                    }
215                }
216            }
217            Some(UnionField_::Value(variant)) => {
218                let value = match &variant {
219                    Variant_::And => {
220                        let value = map.next_value()?;
221                        SearchTemplatesQuery::And(value)
222                    }
223                    Variant_::Or => {
224                        let value = map.next_value()?;
225                        SearchTemplatesQuery::Or(value)
226                    }
227                    Variant_::Not => {
228                        let value = map.next_value()?;
229                        SearchTemplatesQuery::Not(value)
230                    }
231                    Variant_::ExactMatch => {
232                        let value = map.next_value()?;
233                        SearchTemplatesQuery::ExactMatch(value)
234                    }
235                    Variant_::SearchText => {
236                        let value = map.next_value()?;
237                        SearchTemplatesQuery::SearchText(value)
238                    }
239                    Variant_::Label => {
240                        let value = map.next_value()?;
241                        #[allow(deprecated)] SearchTemplatesQuery::Label(value)
242                    }
243                    Variant_::Labels => {
244                        let value = map.next_value()?;
245                        SearchTemplatesQuery::Labels(value)
246                    }
247                    Variant_::Property => {
248                        let value = map.next_value()?;
249                        #[allow(deprecated)] SearchTemplatesQuery::Property(value)
250                    }
251                    Variant_::Properties => {
252                        let value = map.next_value()?;
253                        SearchTemplatesQuery::Properties(value)
254                    }
255                    Variant_::CreatedBy => {
256                        let value = map.next_value()?;
257                        SearchTemplatesQuery::CreatedBy(value)
258                    }
259                    Variant_::IsArchived => {
260                        let value = map.next_value()?;
261                        SearchTemplatesQuery::IsArchived(value)
262                    }
263                    Variant_::IsPublished => {
264                        let value = map.next_value()?;
265                        SearchTemplatesQuery::IsPublished(value)
266                    }
267                    Variant_::Workspace => {
268                        let value = map.next_value()?;
269                        SearchTemplatesQuery::Workspace(value)
270                    }
271                    Variant_::AuthorIsCurrentUser => {
272                        let value = map.next_value()?;
273                        SearchTemplatesQuery::AuthorIsCurrentUser(value)
274                    }
275                    Variant_::AuthorRids => {
276                        let value = map.next_value()?;
277                        SearchTemplatesQuery::AuthorRids(value)
278                    }
279                    Variant_::Unknown(type_) => {
280                        let value = map.next_value()?;
281                        SearchTemplatesQuery::Unknown(Unknown {
282                            type_: type_.clone(),
283                            value,
284                        })
285                    }
286                };
287                if map.next_key::<UnionTypeField_>()?.is_none() {
288                    return Err(de::Error::missing_field("type"));
289                }
290                let type_variant = map.next_value::<Variant_>()?;
291                if variant != type_variant {
292                    return Err(
293                        de::Error::invalid_value(
294                            de::Unexpected::Str(type_variant.as_str()),
295                            &variant.as_str(),
296                        ),
297                    );
298                }
299                value
300            }
301            None => return Err(de::Error::missing_field("type")),
302        };
303        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
304            return Err(de::Error::invalid_length(3, &"type and value fields"));
305        }
306        Ok(v)
307    }
308}
309#[derive(PartialEq)]
310enum Variant_ {
311    And,
312    Or,
313    Not,
314    ExactMatch,
315    SearchText,
316    Label,
317    Labels,
318    Property,
319    Properties,
320    CreatedBy,
321    IsArchived,
322    IsPublished,
323    Workspace,
324    AuthorIsCurrentUser,
325    AuthorRids,
326    Unknown(Box<str>),
327}
328impl Variant_ {
329    fn as_str(&self) -> &'static str {
330        match *self {
331            Variant_::And => "and",
332            Variant_::Or => "or",
333            Variant_::Not => "not",
334            Variant_::ExactMatch => "exactMatch",
335            Variant_::SearchText => "searchText",
336            Variant_::Label => "label",
337            Variant_::Labels => "labels",
338            Variant_::Property => "property",
339            Variant_::Properties => "properties",
340            Variant_::CreatedBy => "createdBy",
341            Variant_::IsArchived => "isArchived",
342            Variant_::IsPublished => "isPublished",
343            Variant_::Workspace => "workspace",
344            Variant_::AuthorIsCurrentUser => "authorIsCurrentUser",
345            Variant_::AuthorRids => "authorRids",
346            Variant_::Unknown(_) => "unknown variant",
347        }
348    }
349}
350impl<'de> de::Deserialize<'de> for Variant_ {
351    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
352    where
353        D: de::Deserializer<'de>,
354    {
355        d.deserialize_str(VariantVisitor_)
356    }
357}
358struct VariantVisitor_;
359impl<'de> de::Visitor<'de> for VariantVisitor_ {
360    type Value = Variant_;
361    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
362        fmt.write_str("string")
363    }
364    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
365    where
366        E: de::Error,
367    {
368        let v = match value {
369            "and" => Variant_::And,
370            "or" => Variant_::Or,
371            "not" => Variant_::Not,
372            "exactMatch" => Variant_::ExactMatch,
373            "searchText" => Variant_::SearchText,
374            "label" => Variant_::Label,
375            "labels" => Variant_::Labels,
376            "property" => Variant_::Property,
377            "properties" => Variant_::Properties,
378            "createdBy" => Variant_::CreatedBy,
379            "isArchived" => Variant_::IsArchived,
380            "isPublished" => Variant_::IsPublished,
381            "workspace" => Variant_::Workspace,
382            "authorIsCurrentUser" => Variant_::AuthorIsCurrentUser,
383            "authorRids" => Variant_::AuthorRids,
384            value => Variant_::Unknown(value.to_string().into_boxed_str()),
385        };
386        Ok(v)
387    }
388}
389///An unknown variant of the SearchTemplatesQuery union.
390#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
391pub struct Unknown {
392    type_: Box<str>,
393    value: conjure_object::Any,
394}
395impl Unknown {
396    /// Returns the unknown variant's type name.
397    #[inline]
398    pub fn type_(&self) -> &str {
399        &self.type_
400    }
401}