-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialize constraints #3
Comments
Serializing error reports was implemented in a989bcb. All that's missing is serializing constraints, which shouldn't be too difficult to implement:
For example: #[derive(garde::Validate)]
struct Foo {
#[garde(length(min = 1))]
s: String,
} Would derive the following: impl garde::Validate for Foo {
// ... the usual validate impl
fn constraints() -> ::garde::Constraints {
use ::garde::constraints::*;
Constraints::Struct(
Struct {
fields: vec![
(
"s".into(),
vec![
Rule::Length {
min: Some(1),
max: None
}
],
)
]
}
)
}
} |
Thinking about this a bit more. Our support for arbitrary If you have e.g. |
It would be useful to support getting a list of constraints on a struct and serializing them to JSON. A possible use-case is sharing the validations between the backend and frontend of a web app without having to manually keep them in sync.
Error messages should also support
serde::Serialize
. Some inspiration could be taken from similar libraries in other ecosystems, such aszod
for TypeScript.The output should respect
rename
.The text was updated successfully, but these errors were encountered: