Skip to content

Custom validations issue in Grape 2.3.0 #2533

Closed
@schinery

Description

@schinery

I've just tried upgrading from Grape 2.2.0 to 2.3.0 and the custom validations I have defined in my project are no longer "working", as in I now get a 'Grape::Validations.require_validator': unknown validator: greater_than_or_equal_to (Grape::Exceptions::UnknownValidator) error when starting a Rails console or server.

The validations currently look like this:

class GreaterThanOrEqualToValidator < Grape::Validations::Validators::Base
  def validate_param!(attr_name, params)
    return unless params.key?(attr_name) && params.key?(@option)
    return if params[attr_name] >= params[@option]

    raise Grape::Exceptions::Validation.new params: [@scope.full_name(attr_name)],
                                            message: "must be greater than or equal to #{@option}"
  end
end

And the validations are defined in a app/validations folder with the API mounted at app/api.

I saw that #2516 had been added as part of the 2.3.0 release, and was wondering if I am missing something that is now needed because of that change which isn't currently in the README?

Project env:

  • Grape 2.3.0
  • Rails 8.0.1
  • Ruby 3.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions