Suppress one of the validation errors from `allow_blank` on a required parameter
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
Using allow_blank validator for the required parameter may lead to two validation errors, but I expected to have only one.
Example:
requires :customer_key, type: String, allow_blank: false
If there is no customer_key parameter in request then we receive the following Grape::Exceptions::ValidationErrors exception:
error
=> #<Grape::Exceptions::ValidationErrors: Grape::Exceptions::ValidationErrors>
error.errors
=> {["customer_key"]=>[#<Grape::Exceptions::Validation: is missing>, #<Grape::Exceptions::Validation: is empty>]}
So we receive
- one error because the required parameter "is missing" and
- another one caused by
allow_blankvalidator because the parameter "is empty"
The second error (produced by the allow_blank) doesn't make sense and looks a bit annoying. The expected behavior is to receive only "is missing" error.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example request using requires :customer_key, type: String, allow_blank: false, then trace the validation handling for a missing parameter. Done means the resulting Grape::Exceptions::ValidationErrors contains only the “is missing” validation and no duplicate “is empty” error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100