Skip to main content

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