You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
miqs1992
changed the title
Overriding per_page_param in Grape
Setting per_page_param in Grape
Mar 13, 2020
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 = {})
fromlib/grape/pagination.rb
to use:perPage
in line 49. I don't think that in the current way asper_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 thepage_param
configuration.grape: 1.3.0
pagy: 3.6.0
api-pagination 4.8.2
The text was updated successfully, but these errors were encountered: