3836d69119
Partially addresses #47424. Had to make changes to spec files because stubbing methods on frozen objects is a mess in RSpec and leads to failures: https://github.com/rspec/rspec-mocks/issues/1190
17 lines
500 B
Ruby
17 lines
500 B
Ruby
# frozen_string_literal: true
|
|
|
|
module API
|
|
module Helpers
|
|
module CustomValidators
|
|
class Absence < Grape::Validations::Base
|
|
def validate_param!(attr_name, params)
|
|
return if params.respond_to?(:key?) && !params.key?(attr_name)
|
|
|
|
raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message(:absence)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
Grape::Validations.register_validator(:absence, ::API::Helpers::CustomValidators::Absence)
|