Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
atomless opened this issue Sep 3, 2015 · 5 comments

Comments

@atomless
Copy link

atomless commented Sep 3, 2015

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>'```
@dblock
Copy link
Member

dblock commented Sep 3, 2015

Boolean is not a Ruby type. That said we should do something similar to this, feel free to PR.

@atomless
Copy link
Author

atomless commented Sep 3, 2015

Thanks @dblock. Right, it's not a Ruby type, but it is in the Grape docs as a valid param validation type. Maybe just requires a note in the docs about including the line Boolean = Virtus::Attribute::Boolean in any helper that specifies it as a type? But yes, the solution you suggest would be cleaner!

@dblock
Copy link
Member

dblock commented Sep 3, 2015

I am not sure what the best implementation is, but we should be able to resolve Boolean to API::Boolean and eventually to Virtus::....

@towanda
Copy link
Contributor

towanda commented Sep 14, 2015

This can be closed, It's fixed here: #1153

@dblock dblock closed this as completed Sep 14, 2015
@dblock
Copy link
Member

dblock commented Sep 14, 2015

Closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants