Skip to content

Suppress one of the validation errors from allow_blank on a required parameter #2187

@andrykonchin

Description

@andrykonchin

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_blank validator 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions