So I have a rails application that use jsonapi-resources gem and in global config specified this config
JSONAPI.configure do |config|
config.maximum_page_size = 1000
end
https://jsonapi-resources.com/v0.10/guide/basic_usage.html
But I want to use custom maximum_page_size in separate API resources for example /api/logs
module Api
class LogResource < ApplicationResource
immutable
model_name 'Api::Log'
primary_key :uuid
def self.default_sort
[{ field: 'time_start', direction: :desc }]
end
end
end
SO My question how to specify config only for this specific JSON API resource?
From what I can determine in the source code
maximum_page_sizecannot be directly overridden at a resource level, so it appears the best way to handle this would be to implement a customPaginator.For your given example I think something as simple as the following should work:
Then you should be able to specify the
Paginatorfor your resourceIf you need to make this more flexible e.g. not a fixed constant. Then we would need to create a method that dynamically creates a class on on the fly with the appropriate limitation set and then utilize that as the
Paginator, something like.Then use as
Please Note: I have not used this library so there may be better solutions.