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
//! Actix-web wrapper for [garde](https://github.com/jprochazk/garde), a Rust validation library.
//!
//! # Installation
//!
//! ```toml
//! [dependencies]
//! garde = "0.22"
//! garde-actix-web = "0.12"
//! ```
//!
//! # Usage example
//!
//! Simply use `garde-actix-web` exposed types as a drop in for actix types.
//!
//! Your types must implement `Validate` from `garde`. Validation happens during actix's `FromRequest` invocation.
//!
//! If the payload is invalid, a 400 error is returned (404 for Path).
//!
//! Custom error handling can be implemented with an extractor config (`garde_actix_web::web::QueryConfig` in place of `actix_web::web::QueryConfig` for example).
//!
//! ```rust
//! use actix_web::HttpResponse;
//! // instead of actix_web::web::Path
//! use garde_actix_web::web::Path;
//! use garde::Validate;
//!
//! #[derive(Validate)]
//! struct MyStruct<'a> {
//! #[garde(ascii, length(min=3, max=25))]
//! username: &'a str,
//! }
//!
//! fn test(id: Path<MyStruct>) -> HttpResponse {
//! todo!()
//! }
//! ```
//!
//! ⚠️ When using `garde` [custom validation](https://github.com/jprochazk/garde#custom-validation), the `Context` type needs to implement `Default` which is not required by `garde`.
//!
//! # Feature flags
//!
//! | name | description | extra dependencies |
//! |------------|---------------------------------------------------------------|----------------------------------------------------------------------------------------------|
//! | `serde_qs` | Enables the usage of `garde` for `serde_qs::actix::QsQuery<T>` | [`serde_qs`](https://crates.io/crates/serde_qs) |
//!
//! # Compatibility matrix
//!
//! | garde version | serde_qs version | garde-actix-web-version |
//! |---------------|------------------|-------------------------|
//! | `0.14` | `0.12` | `0.1.x` |
//! | `0.15` | `0.12` | `0.2.x` |
//! | `0.16` | `0.12` | `0.3.x` |
//! | `0.17` | `0.12` | `0.4.x` |
//! | `0.18` | `0.12` | `0.5.x`, `0.6.x` |
//! | `0.18` | `0.13` | `0.7.x` |
//! | `0.19` | `0.13` | `0.8.x` |
//! | `0.20` | `0.13` | `0.9.x` |
//! | `0.20` | `0.13` | `0.10.x` |
//! | `0.22` | `0.13` | `0.11.x` |
//! | `0.22` | `0.15` | `0.12.x` |
use HttpRequest;
use Data;
use Validate;