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

Reusable params helpers are not inherited. #2113

Open
dim opened this issue Oct 8, 2020 · 2 comments
Open

Reusable params helpers are not inherited. #2113

dim opened this issue Oct 8, 2020 · 2 comments
Labels

Comments

@dim
Copy link
Contributor

dim commented Oct 8, 2020

If you mount a child API within a parent API, all helper methods are correctly inherited from parent to child, but not params helpers, for example:

class Child < Grape::API
  get '/child' do
    respond_with_ok
  end
end

class Parent < Grape::API
  helpers do
    def respond_with_ok
      { status: 'ok' }
    end
  end

  get '/parent' do
    respond_with_ok
  end

  mount Child
end
$ curl http://127.0.0.1:8080/parent  # => {:status=>"ok"}
$ curl http://127.0.0.1:8080/child    # => {:status=>"ok"}

The same doesn't really work for params, e.g:

class Child < Grape::API
  params do 
    use :page
  end
  get '/child' do
    params
  end
end

class Parent < Grape::API
  helpers do
    params :page do
      optional :page, type: Integer
    end
  end

  params do 
    use :page
  end
  get '/parent' do
    params
  end

  mount Child
end

Results in a:

RuntimeError: Params :page not found!
@dblock
Copy link
Member

dblock commented Oct 8, 2020

Turn it into a spec on HEAD?

@dim
Copy link
Contributor Author

dim commented Oct 8, 2020

Sure, please see #2114 but I am not sure it's a simple fix. The params blocks are being evaluated at load time (and not e.g. on first access) which means that shared helpers are not even defined at this point.

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

No branches or pull requests

2 participants