Skip to content
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

Add #[garde(allow_unvalidated)] #43

Closed
jprochazk opened this issue May 10, 2023 · 1 comment
Closed

Add #[garde(allow_unvalidated)] #43

jprochazk opened this issue May 10, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@jprochazk
Copy link
Owner

Currently, the following will fail to compile:

#[derive(Validate)]
struct Foo {
  value: String,
}

The user has to add #[garde(skip)] if they don't intend to validate the value field. It should instead be possible to add #[garde(allow_unvalidated)] to the struct at the top level which would ignore these errors for all fields. This is useful when there are many fields which the user doesn't want to validate. Currently, you have to add #[garde(skip)] to each one, which can get verbose very quickly.

#[derive(Validate)]
struct Foo {
  #[garde(length(min=1))]
  bar: String,
  #[garde(skip)]
  baz: i32,
  #[garde(skip)]
  qux: Qux,
  #[garde(skip)]
  fred: Etc,
}

#[derive(Validate)]
#[garde(allow_unvalidated)]
struct Foo {
  #[garde(length(min=1))]
  bar: String,
  baz: i32,
  qux: Qux,
  fred: Etc,
}
@jprochazk jprochazk added the enhancement New feature or request label May 16, 2023
@jprochazk
Copy link
Owner Author

Added in v0.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant