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

Setting per_page_param in Grape #126

Open
miqs1992 opened this issue Mar 13, 2020 · 0 comments
Open

Setting per_page_param in Grape #126

miqs1992 opened this issue Mar 13, 2020 · 0 comments

Comments

@miqs1992
Copy link

As my API will be used by a frontend app I wanted to set per_page_param as camel-cased :perPage instead of the default :per_page.
I used the described in the documentation configuration method which resulted in ArgumentError: comparison of Integer with String failed. After checking swagger docs I noticed that endpoint is still accepting only :per_page while pagination method is trying to fetch :perPage value from params.
I tried to add optional :perPage, type: Integer to my endpoint params, but now both :perPage and :per_page were available in the swagger docs.
I ended up in monkey patching def self.paginate(options = {}) from lib/grape/pagination.rb to use :perPage in line 49. I don't think that in the current way as per_page_param= is evaluated we can read the key from any variable (it is assigning a lambda to @per_page_param).
Maybe we can add @per_page_param_key to allow reading configured key? Same goes for the page_param configuration.

grape: 1.3.0
pagy: 3.6.0
api-pagination 4.8.2

@miqs1992 miqs1992 changed the title Overriding per_page_param in Grape Setting per_page_param in Grape Mar 13, 2020
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

1 participant