Skip to content

Using type: Boolean in a param validation throws an error when placed in a helper file. #1144

@atomless

Description

@atomless

This works fine:

params do
  requires :toggle_prm, type: Boolean
end
post 'endpoint' do
  # ...
end

However, when placed in an external helper file like so:

module ParamValidation
  extend Grape::API::Helpers

  params :requires_toggle_prm do
    requires :toggle_prm, type: Boolean
  end

end

it throws the error shown below:

/Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/v1/param_validation.rb:26:in `block in <module:ParamValidation>': uninitialized constant ParamValidation::Boolean (NameError)
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/parameters.rb:39:in `instance_exec'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/parameters.rb:39:in `block in use'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/parameters.rb:35:in `each'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/parameters.rb:35:in `use'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/v1/v1.rb:72:in `block (5 levels) in <class:V1>'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/validations/params_scope.rb:30:in `instance_eval'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/validations/params_scope.rb:30:in `initialize'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/validations.rb:23:in `new'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/validations.rb:23:in `params'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/v1/v1.rb:71:in `block (4 levels) in <class:V1>'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `instance_eval'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `block in nest'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `each'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `nest'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/routing.rb:154:in `block in namespace'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/settings.rb:136:in `within_namespace'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/routing.rb:151:in `namespace'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/v1/v1.rb:68:in `block (3 levels) in <class:V1>'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `instance_eval'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `block in nest'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `each'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `nest'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/routing.rb:154:in `block in namespace'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/settings.rb:136:in `within_namespace'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/routing.rb:151:in `namespace'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/v1/v1.rb:62:in `block (2 levels) in <class:V1>'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `instance_eval'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `block in nest'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `each'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `nest'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/routing.rb:154:in `block in namespace'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/settings.rb:136:in `within_namespace'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/routing.rb:151:in `namespace'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/v1/v1.rb:58:in `block in <class:V1>'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `instance_eval'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `block in nest'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `each'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/api.rb:79:in `nest'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/routing.rb:154:in `block in namespace'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/settings.rb:136:in `within_namespace'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/grape-0.13.1/lib/grape/dsl/routing.rb:151:in `namespace'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/v1/v1.rb:30:in `<class:V1>'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/v1/v1.rb:5:in `<module:API>'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/v1/v1.rb:4:in `<module:SoastaDOC>'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/v1/v1.rb:3:in `<top (required)>'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/api.rb:6:in `require_relative'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/server/api/api.rb:6:in `<top (required)>'
    from /Users/jamestindall/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/jamestindall/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/config.ru:6:in `block in <main>'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/config.ru:in `new'
    from /Users/jamestindall/Documents/soasta/DOC/source/g-speak/Baton/BatonSite/dist/config.ru:in `<main>'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/lib/rack/server.rb:272:in `start'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/lib/rack/server.rb:147:in `start'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.6.4/bin/rackup:4:in `<top (required)>'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/bin/rackup:23:in `load'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/bin/rackup:23:in `<main>'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `eval'
    from /Users/jamestindall/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `<main>'```

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