Skip to content

Setting per_page_param in Grape #126

@miqs1992

Description

@miqs1992

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions