diff --git a/CHANGELOG.md b/CHANGELOG.md index b7d0ae5e76..ce94a5b18d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * [#1486](https://github.com/ruby-grape/grape/pull/1486): Implemented except in values validator - [@jonmchan](https://github.com/jonmchan). * [#1470](https://github.com/ruby-grape/grape/pull/1470): Drop support for ruby-2.0 - [@namusyaka](https://github.com/namusyaka). * [#1490](https://github.com/ruby-grape/grape/pull/1490): Switch to Ruby-2.x+ syntax - [@namusyaka](https://github.com/namusyaka). +* [#1499](https://github.com/ruby-grape/grape/pull/1499): Support fail_fast param validation option - [@dgasper](https://github.com/dgasper). * Your contribution here. #### Fixes diff --git a/README.md b/README.md index 116e305869..ca40ae39e8 100644 --- a/README.md +++ b/README.md @@ -1355,6 +1355,23 @@ subject.rescue_from Grape::Exceptions::ValidationErrors do |e| end ``` +Grape returns all validation and coercion errors found by default. To skip all subsequent validation checks when a specific param is found invalid, use `fail_fast: true`. +For example: +```ruby +params do + required :beer, fail_fast: true + required :wine +end +``` +will not check if `:wine` is present unless it finds `:beer`. The result of empty params would be a single `Grape::Exceptions::ValidationErrors` error. +Similarly +```ruby +params do + required :blah, allow_blank: false, regexp: /blah/, fail_fast: true +end +``` +will not check if the `:blah` matches the regular expression if it is blank. + ### I18n Grape supports I18n for parameter-related error messages, but will fallback to English if