api-pagination
api-pagination copied to clipboard
Setting per_page_param in Grape
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