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

Incorrect generate Links for Headers #118

Open
kvandake opened this issue Jan 29, 2019 · 1 comment
Open

Incorrect generate Links for Headers #118

kvandake opened this issue Jan 29, 2019 · 1 comment

Comments

@kvandake
Copy link

kvandake commented Jan 29, 2019

When I configure custom parameters for library I get incorrect links for headers.

For example,

ApiPagination.configure do |config|

   ...

  # If you have more than one gem included, you can choose a paginator.
  config.paginator = :pagy # or :will_paginate

  # Optional: what parameter should be used to set the page option
  config.page_param do |params|
    params[:page][:number] if params[:page].is_a?(ActionController::Parameters)
  end

  # Optional: what parameter should be used to set the per page option
  config.per_page_param do |params|
    params[:page][:size] if params[:page].is_a?(ActionController::Parameters)
  end

   ...

end

Some response,

Link →<http://localhost:3000/api/reviews?page=1>; rel="first", <http://localhost:3000/api/reviews?page=2>; rel="prev", <http://localhost:3000/api/reviews?page=5>; rel="last", <http://localhost:3000/api/reviews?page=4>; rel="next"
X-Per-Page →20
X-Page →3
X-Total →86

Maybe is it hardcode?

@kvandake kvandake changed the title Incorrect genearate Links for Headers Incorrect generate Links for Headers Jan 29, 2019
@davidcelis
Copy link
Owner

davidcelis commented Jan 29, 2019

Yeah, it looks like both Rails and grape just hardcode page as the parameter name despite configuration.

To be honest, I'm not sure how to solve this given how the configuration class currently works. The configuration options for the page and per_page parameter names take a block, and the block can contain anything. There can be any sort of nesting within the params hash, and I can't see any way of actually retrieving the names themselves so that I can just set the new param.

This issue makes me think that the method for configuring these parameter names itself is flawed and would need to be changed, which would be a breaking change. Or maybe it wouldn't be, since this technically doesn't work.

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

No branches or pull requests

2 participants