api-bones 4.0.0

Opinionated REST API types: errors (RFC 9457), pagination, health checks, and more
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
//! Query parameter types for list endpoints.
//!
//! Provides reusable structs for sorting, filtering, and full-text search
//! so consumers don't reinvent query parameter handling for every collection endpoint.
//!
//! # Overview
//!
//! - [`SortDirection`] — ascending or descending order
//! - [`SortParams`] — field name + direction
//! - [`FilterParams`] — field/operator/value triples for structured filtering
//! - [`SearchParams`] — full-text query with optional field scoping

#[cfg(all(not(feature = "std"), feature = "alloc"))]
use alloc::{string::String, vec::Vec};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(all(feature = "validator", any(feature = "std", feature = "alloc")))]
use validator::Validate;

// ---------------------------------------------------------------------------
// SortDirection
// ---------------------------------------------------------------------------

/// Sort order for list endpoints.
///
/// # Examples
///
/// ```
/// use api_bones::query::SortDirection;
///
/// assert_eq!(SortDirection::default(), SortDirection::Asc);
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(
    feature = "serde",
    derive(Serialize, Deserialize),
    serde(rename_all = "lowercase")
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "proptest", derive(proptest_derive::Arbitrary))]
pub enum SortDirection {
    /// Ascending order (A → Z, 0 → 9).
    #[default]
    Asc,
    /// Descending order (Z → A, 9 → 0).
    Desc,
}

// ---------------------------------------------------------------------------
// SortParams
// ---------------------------------------------------------------------------

#[cfg(all(feature = "serde", any(feature = "std", feature = "alloc")))]
fn default_sort_direction() -> SortDirection {
    SortDirection::Asc
}

/// Query parameters for sorting a collection endpoint.
///
/// ```json
/// {"sort_by": "created_at", "direction": "desc"}
/// ```
#[cfg(any(feature = "std", feature = "alloc"))]
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "proptest", derive(proptest_derive::Arbitrary))]
pub struct SortParams {
    /// The field name to sort by (e.g. `"created_at"`, `"name"`).
    pub sort_by: String,
    /// Sort direction. Defaults to [`SortDirection::Asc`].
    #[cfg_attr(feature = "serde", serde(default = "default_sort_direction"))]
    pub direction: SortDirection,
}

#[cfg(any(feature = "std", feature = "alloc"))]
impl SortParams {
    /// Create sort params with the given field and direction.
    ///
    /// # Examples
    ///
    /// ```
    /// use api_bones::query::{SortParams, SortDirection};
    ///
    /// let p = SortParams::new("created_at", SortDirection::Desc);
    /// assert_eq!(p.sort_by, "created_at");
    /// assert_eq!(p.direction, SortDirection::Desc);
    /// ```
    #[must_use]
    pub fn new(sort_by: impl Into<String>, direction: SortDirection) -> Self {
        Self {
            sort_by: sort_by.into(),
            direction,
        }
    }

    /// Create sort params with ascending direction.
    ///
    /// # Examples
    ///
    /// ```
    /// use api_bones::query::{SortParams, SortDirection};
    ///
    /// let p = SortParams::asc("name");
    /// assert_eq!(p.direction, SortDirection::Asc);
    /// ```
    #[must_use]
    pub fn asc(sort_by: impl Into<String>) -> Self {
        Self::new(sort_by, SortDirection::Asc)
    }

    /// Create sort params with descending direction.
    ///
    /// # Examples
    ///
    /// ```
    /// use api_bones::query::{SortParams, SortDirection};
    ///
    /// let p = SortParams::desc("created_at");
    /// assert_eq!(p.direction, SortDirection::Desc);
    /// ```
    #[must_use]
    pub fn desc(sort_by: impl Into<String>) -> Self {
        Self::new(sort_by, SortDirection::Desc)
    }
}

// ---------------------------------------------------------------------------
// FilterParams
// ---------------------------------------------------------------------------

/// A single filter triple: `field`, `operator`, `value`.
///
/// ```json
/// {"field": "status", "operator": "eq", "value": "active"}
/// ```
#[cfg(any(feature = "std", feature = "alloc"))]
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "proptest", derive(proptest_derive::Arbitrary))]
pub struct FilterEntry {
    /// The field name to filter on.
    pub field: String,
    /// The comparison operator (e.g. `"eq"`, `"neq"`, `"gt"`, `"lt"`, `"contains"`).
    pub operator: String,
    /// The value to compare against.
    pub value: String,
}

#[cfg(any(feature = "std", feature = "alloc"))]
impl FilterEntry {
    /// Create a filter entry.
    ///
    /// # Examples
    ///
    /// ```
    /// use api_bones::query::FilterEntry;
    ///
    /// let entry = FilterEntry::new("status", "eq", "active");
    /// assert_eq!(entry.field, "status");
    /// assert_eq!(entry.operator, "eq");
    /// assert_eq!(entry.value, "active");
    /// ```
    #[must_use]
    pub fn new(
        field: impl Into<String>,
        operator: impl Into<String>,
        value: impl Into<String>,
    ) -> Self {
        Self {
            field: field.into(),
            operator: operator.into(),
            value: value.into(),
        }
    }
}

/// Query parameters for structured filtering on a collection endpoint.
///
/// Each entry is a field/operator/value triple. Multiple entries are
/// AND-combined by convention; consumers may choose different semantics.
///
/// ```json
/// {"filters": [{"field": "status", "operator": "eq", "value": "active"}]}
/// ```
#[cfg(any(feature = "std", feature = "alloc"))]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "proptest", derive(proptest_derive::Arbitrary))]
pub struct FilterParams {
    /// The list of filter entries.
    #[cfg_attr(feature = "serde", serde(default))]
    pub filters: Vec<FilterEntry>,
}

#[cfg(any(feature = "std", feature = "alloc"))]
impl FilterParams {
    /// Create filter params from an iterator of entries.
    ///
    /// # Examples
    ///
    /// ```
    /// use api_bones::query::{FilterParams, FilterEntry};
    ///
    /// let f = FilterParams::new([FilterEntry::new("status", "eq", "active")]);
    /// assert!(!f.is_empty());
    /// assert_eq!(f.filters.len(), 1);
    /// ```
    #[must_use]
    pub fn new(filters: impl IntoIterator<Item = FilterEntry>) -> Self {
        Self {
            filters: filters.into_iter().collect(),
        }
    }

    /// Returns `true` if no filters are set.
    ///
    /// # Examples
    ///
    /// ```
    /// use api_bones::query::FilterParams;
    ///
    /// let f = FilterParams::default();
    /// assert!(f.is_empty());
    /// ```
    #[must_use]
    pub fn is_empty(&self) -> bool {
        self.filters.is_empty()
    }
}

// ---------------------------------------------------------------------------
// SearchParams
// ---------------------------------------------------------------------------

/// Query parameters for full-text search on a collection endpoint.
///
/// `query` is the search string. `fields` optionally scopes the search
/// to specific fields; when omitted the backend decides which fields to search.
///
/// ```json
/// {"query": "annual report", "fields": ["title", "description"]}
/// ```
#[cfg(any(feature = "std", feature = "alloc"))]
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema, utoipa::IntoParams))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "validator", derive(Validate))]
#[cfg_attr(feature = "proptest", derive(proptest_derive::Arbitrary))]
pub struct SearchParams {
    /// The search string. Must not exceed 500 characters.
    #[cfg_attr(
        feature = "validator",
        validate(length(
            min = 1,
            max = 500,
            message = "query must be between 1 and 500 characters"
        ))
    )]
    #[cfg_attr(feature = "proptest", proptest(strategy = "search_query_strategy()"))]
    pub query: String,
    /// Optional list of field names to scope the search to.
    #[cfg_attr(
        feature = "serde",
        serde(default, skip_serializing_if = "Vec::is_empty")
    )]
    pub fields: Vec<String>,
}

#[cfg(any(feature = "std", feature = "alloc"))]
impl SearchParams {
    /// Create search params targeting all fields.
    ///
    /// # Examples
    ///
    /// ```
    /// use api_bones::query::SearchParams;
    ///
    /// let s = SearchParams::new("annual report");
    /// assert_eq!(s.query, "annual report");
    /// assert!(s.fields.is_empty());
    /// ```
    #[must_use]
    pub fn new(query: impl Into<String>) -> Self {
        Self {
            query: query.into(),
            fields: Vec::new(),
        }
    }

    /// Create validated search params — enforces 1–500 char constraint without `validator` feature.
    ///
    /// # Examples
    ///
    /// ```
    /// use api_bones::query::SearchParams;
    ///
    /// let s = SearchParams::try_new("annual report").unwrap();
    /// assert_eq!(s.query, "annual report");
    ///
    /// assert!(SearchParams::try_new("").is_err());
    /// assert!(SearchParams::try_new("a".repeat(501)).is_err());
    /// ```
    pub fn try_new(query: impl Into<String>) -> Result<Self, crate::error::ValidationError> {
        let query = query.into();
        if query.is_empty() || query.len() > 500 {
            return Err(crate::error::ValidationError {
                field: "/query".into(),
                message: "must be between 1 and 500 characters".into(),
                rule: Some("length".into()),
            });
        }
        Ok(Self {
            query,
            fields: Vec::new(),
        })
    }

    /// Create validated search params scoped to specific fields.
    ///
    /// # Examples
    ///
    /// ```
    /// use api_bones::query::SearchParams;
    ///
    /// let s = SearchParams::try_with_fields("report", ["title"]).unwrap();
    /// assert_eq!(s.fields, vec!["title"]);
    ///
    /// assert!(SearchParams::try_with_fields("", ["title"]).is_err());
    /// ```
    pub fn try_with_fields(
        query: impl Into<String>,
        fields: impl IntoIterator<Item = impl Into<String>>,
    ) -> Result<Self, crate::error::ValidationError> {
        let mut s = Self::try_new(query)?;
        s.fields = fields.into_iter().map(Into::into).collect();
        Ok(s)
    }

    /// Create search params scoped to specific fields.
    ///
    /// # Examples
    ///
    /// ```
    /// use api_bones::query::SearchParams;
    ///
    /// let s = SearchParams::with_fields("report", ["title", "description"]);
    /// assert_eq!(s.query, "report");
    /// assert_eq!(s.fields, vec!["title", "description"]);
    /// ```
    #[must_use]
    pub fn with_fields(
        query: impl Into<String>,
        fields: impl IntoIterator<Item = impl Into<String>>,
    ) -> Self {
        Self {
            query: query.into(),
            fields: fields.into_iter().map(Into::into).collect(),
        }
    }
}

// ---------------------------------------------------------------------------
// Axum extractors — `axum` feature
// ---------------------------------------------------------------------------

#[cfg(feature = "axum")]
#[allow(clippy::result_large_err)]
mod axum_extractors {
    use super::SortParams;
    use crate::error::ApiError;
    use axum::extract::{FromRequestParts, Query};
    use axum::http::request::Parts;

    impl<S: Send + Sync> FromRequestParts<S> for SortParams {
        type Rejection = ApiError;

        async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
            let Query(params) = Query::<Self>::from_request_parts(parts, state)
                .await
                .map_err(|e| ApiError::bad_request(e.to_string()))?;
            Ok(params)
        }
    }
}

// ---------------------------------------------------------------------------
// proptest strategy helpers
// ---------------------------------------------------------------------------

#[cfg(all(feature = "proptest", any(feature = "std", feature = "alloc")))]
fn search_query_strategy() -> impl proptest::strategy::Strategy<Value = String> {
    proptest::string::string_regex("[a-zA-Z0-9 ]{1,500}").expect("valid regex")
}

// ---------------------------------------------------------------------------
// arbitrary::Arbitrary manual impl — constrained SearchParams
// ---------------------------------------------------------------------------

#[cfg(all(feature = "arbitrary", any(feature = "std", feature = "alloc")))]
impl<'a> arbitrary::Arbitrary<'a> for SearchParams {
    fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
        // Generate a query length between 1 and 500, then fill with arbitrary bytes
        // mapped to printable ASCII (32–126) to satisfy the validator constraint.
        let len = u.int_in_range(1usize..=500)?;
        let query: String = (0..len)
            .map(|_| -> arbitrary::Result<char> {
                let byte = u.int_in_range(32u8..=126)?;
                Ok(char::from(byte))
            })
            .collect::<arbitrary::Result<_>>()?;
        let fields = <Vec<String> as arbitrary::Arbitrary>::arbitrary(u)?;
        Ok(Self { query, fields })
    }
}

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------

#[cfg(test)]
mod tests {
    use super::*;

    // --- SortDirection ---

    #[test]
    fn sort_direction_default_is_asc() {
        assert_eq!(SortDirection::default(), SortDirection::Asc);
    }

    #[cfg(feature = "serde")]
    #[test]
    fn sort_direction_serde_lowercase() {
        let asc = serde_json::to_value(SortDirection::Asc).unwrap();
        assert_eq!(asc, serde_json::json!("asc"));
        let desc = serde_json::to_value(SortDirection::Desc).unwrap();
        assert_eq!(desc, serde_json::json!("desc"));

        let back: SortDirection = serde_json::from_value(asc).unwrap();
        assert_eq!(back, SortDirection::Asc);
    }

    // --- SortParams ---

    #[test]
    fn sort_params_asc_helper() {
        let p = SortParams::asc("created_at");
        assert_eq!(p.sort_by, "created_at");
        assert_eq!(p.direction, SortDirection::Asc);
    }

    #[test]
    fn sort_params_desc_helper() {
        let p = SortParams::desc("name");
        assert_eq!(p.sort_by, "name");
        assert_eq!(p.direction, SortDirection::Desc);
    }

    #[cfg(feature = "serde")]
    #[test]
    fn sort_params_serde_round_trip() {
        let p = SortParams::desc("created_at");
        let json = serde_json::to_value(&p).unwrap();
        assert_eq!(json["sort_by"], "created_at");
        assert_eq!(json["direction"], "desc");
        let back: SortParams = serde_json::from_value(json).unwrap();
        assert_eq!(back, p);
    }

    #[cfg(feature = "serde")]
    #[test]
    fn sort_params_serde_default_direction() {
        let json = serde_json::json!({"sort_by": "name"});
        let p: SortParams = serde_json::from_value(json).unwrap();
        assert_eq!(p.direction, SortDirection::Asc);
    }

    // --- FilterParams ---

    #[test]
    fn filter_params_default_is_empty() {
        let f = FilterParams::default();
        assert!(f.is_empty());
    }

    #[test]
    fn filter_params_new() {
        let f = FilterParams::new([FilterEntry::new("status", "eq", "active")]);
        assert!(!f.is_empty());
        assert_eq!(f.filters.len(), 1);
        assert_eq!(f.filters[0].field, "status");
        assert_eq!(f.filters[0].operator, "eq");
        assert_eq!(f.filters[0].value, "active");
    }

    #[cfg(feature = "serde")]
    #[test]
    fn filter_params_serde_round_trip() {
        let f = FilterParams::new([FilterEntry::new("age", "gt", "18")]);
        let json = serde_json::to_value(&f).unwrap();
        let back: FilterParams = serde_json::from_value(json).unwrap();
        assert_eq!(back, f);
    }

    #[cfg(feature = "serde")]
    #[test]
    fn filter_params_serde_empty_filters_default() {
        let json = serde_json::json!({});
        let f: FilterParams = serde_json::from_value(json).unwrap();
        assert!(f.is_empty());
    }

    // --- SearchParams ---

    #[test]
    fn search_params_new() {
        let s = SearchParams::new("annual report");
        assert_eq!(s.query, "annual report");
        assert!(s.fields.is_empty());
    }

    #[test]
    fn search_params_with_fields() {
        let s = SearchParams::with_fields("report", ["title", "description"]);
        assert_eq!(s.query, "report");
        assert_eq!(s.fields, vec!["title", "description"]);
    }

    #[cfg(feature = "serde")]
    #[test]
    fn search_params_serde_round_trip() {
        let s = SearchParams::with_fields("hello", ["name"]);
        let json = serde_json::to_value(&s).unwrap();
        assert_eq!(json["query"], "hello");
        assert_eq!(json["fields"], serde_json::json!(["name"]));
        let back: SearchParams = serde_json::from_value(json).unwrap();
        assert_eq!(back, s);
    }

    #[cfg(feature = "serde")]
    #[test]
    fn search_params_serde_omits_empty_fields() {
        let s = SearchParams::new("test");
        let json = serde_json::to_value(&s).unwrap();
        assert!(json.get("fields").is_none());
    }

    #[cfg(feature = "validator")]
    #[test]
    fn search_params_validate_empty_query_fails() {
        use validator::Validate;
        let s = SearchParams::new("");
        assert!(s.validate().is_err());
    }

    #[cfg(feature = "validator")]
    #[test]
    fn search_params_validate_too_long_fails() {
        use validator::Validate;
        let s = SearchParams::new("a".repeat(501));
        assert!(s.validate().is_err());
    }

    #[cfg(feature = "validator")]
    #[test]
    fn search_params_validate_boundary_max() {
        use validator::Validate;
        let s = SearchParams::new("a".repeat(500));
        assert!(s.validate().is_ok());
    }

    // -----------------------------------------------------------------------
    // SearchParams::try_new / try_with_fields — fallible constructors
    // -----------------------------------------------------------------------

    #[test]
    fn search_params_try_new_valid() {
        let s = SearchParams::try_new("report").unwrap();
        assert_eq!(s.query, "report");
        assert!(s.fields.is_empty());
    }

    #[test]
    fn search_params_try_new_boundary_min() {
        assert!(SearchParams::try_new("a").is_ok());
    }

    #[test]
    fn search_params_try_new_boundary_max() {
        assert!(SearchParams::try_new("a".repeat(500)).is_ok());
    }

    #[test]
    fn search_params_try_new_empty_fails() {
        let err = SearchParams::try_new("").unwrap_err();
        assert_eq!(err.field, "/query");
        assert_eq!(err.rule.as_deref(), Some("length"));
    }

    #[test]
    fn search_params_try_new_too_long_fails() {
        assert!(SearchParams::try_new("a".repeat(501)).is_err());
    }

    #[test]
    fn search_params_try_with_fields_valid() {
        let s = SearchParams::try_with_fields("report", ["title", "body"]).unwrap();
        assert_eq!(s.query, "report");
        assert_eq!(s.fields, vec!["title", "body"]);
    }

    #[test]
    fn search_params_try_with_fields_empty_query_fails() {
        assert!(SearchParams::try_with_fields("", ["title"]).is_err());
    }

    #[cfg(feature = "axum")]
    mod axum_extractor_tests {
        use super::super::{SortDirection, SortParams};
        use axum::extract::FromRequestParts;
        use axum::http::Request;

        async fn extract(q: &str) -> Result<SortParams, u16> {
            let req = Request::builder().uri(format!("/?{q}")).body(()).unwrap();
            let (mut parts, ()) = req.into_parts();
            SortParams::from_request_parts(&mut parts, &())
                .await
                .map_err(|e| e.status)
        }

        #[tokio::test]
        async fn sort_default_direction() {
            let p = extract("sort_by=name").await.unwrap();
            assert_eq!(p.sort_by, "name");
            assert_eq!(p.direction, SortDirection::Asc);
        }

        #[tokio::test]
        async fn sort_custom_direction() {
            let p = extract("sort_by=created_at&direction=desc").await.unwrap();
            assert_eq!(p.direction, SortDirection::Desc);
        }

        #[tokio::test]
        async fn sort_missing_sort_by_rejected() {
            assert_eq!(extract("").await.unwrap_err(), 400);
        }
    }

    #[cfg(feature = "validator")]
    #[test]
    fn search_params_validate_ok() {
        use validator::Validate;
        let s = SearchParams::new("valid query");
        assert!(s.validate().is_ok());
    }
}