module Grape::DSL::Validations::ClassMethods

Public Instance Methods

document_attribute(names, opts) click to toggle source
# File lib/grape/dsl/validations.rb, line 45
def document_attribute(names, opts)
  setting = description_field(:params)
  setting ||= description_field(:params, {})
  Array(names).each do |name|
    full_name = name[:full_name].to_s
    setting[full_name] ||= {}
    setting[full_name].merge!(opts)

    namespace_stackable(:params, full_name => opts)
  end
end
params(&block) click to toggle source

Opens a root-level ParamsScope, defining parameter coercions and validations for the endpoint. @yield instance context of the new scope

# File lib/grape/dsl/validations.rb, line 41
def params(&block)
  Grape::Validations::ParamsScope.new(api: self, type: Hash, &block)
end
reset_validations!() click to toggle source

Clears all defined parameters and validations. The main purpose of it is to clean up settings, so next endpoint won't interfere with previous one.

params do
  # params for the endpoint below this block
end
post '/current' do
  # whatever
end

# somewhere between them the reset_validations! method gets called

params do
  # params for the endpoint below this block
end
post '/next' do
  # whatever
end
# File lib/grape/dsl/validations.rb, line 31
def reset_validations!
  unset_namespace_stackable :declared_params
  unset_namespace_stackable :validations
  unset_namespace_stackable :params
  unset_description_field :params
end