api-pagination
api-pagination copied to clipboard
Incorrect generate Links for Headers
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?
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.