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

Custom pagination clsss #883

Open
1 task
philkobby opened this issue Aug 22, 2024 · 2 comments
Open
1 task

Custom pagination clsss #883

philkobby opened this issue Aug 22, 2024 · 2 comments
Labels
enhancement New feature or request validated

Comments

@philkobby
Copy link

philkobby commented Aug 22, 2024

Scribe version

4.37

Your question

Hi, I have a custom pagination class that extends Illuminate\Pagination\LengthAwarePaginator, and it's been bound in the service container. This works fine with the paginate() method. However, Scribe seems to instantiate the Illuminate\Pagination\LengthAwarePaginator class directly, which overrides the custom pagination class when generating documentation.

  #[ResponseFromApiResource(
        TaskCollection::class,
        Task::class,
        paginate: 15,
        status: 200,
        description: 'Request was successful',
        collection: true,
    )]

    public function index(Request $request)
    {
        return new TaskCollection(Task::paginate(15));
        //paginations are generated as expected but the documentation does not follow the same format as expected
    }

Is there a workaround for Scribe to resolve the custom pagination class instead of Illuminate\Pagination\LengthAwarePaginator?

Docs

@shalvah
Copy link
Contributor

shalvah commented Aug 24, 2024

I guess we could change it to go through the service container. PR welcome!

@shalvah shalvah closed this as completed Aug 24, 2024
@shalvah shalvah reopened this Aug 24, 2024
@shalvah shalvah added validated enhancement New feature or request and removed triage question labels Nov 5, 2024
@J5Dev
Copy link

J5Dev commented Feb 7, 2025

Did you find a solution or workaround for this @philkobby as I am in the same position, in that we use the Spatie/laravel-json-api-paginate package, and wanted to have our docs represent the pagination structure.

I am open to putting something together when I get some time, however thought I would check before diving too far in.

My thinking is it s'should' be relatively simple as Knuckles\Scribe\Extracting\Shared\TransformerResponseTools Line 31 just needs the ability to have a dynamic Paginator spun up.

Initial thought is to instantiate the Paginator using a specified class from in the Scribe config, and update the parser to allow additional config to be passed via the field arguments in the same way size is etc.

Interested to see if already solved as said, but if not what peoples thoughts are on this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request validated
Projects
None yet
Development

No branches or pull requests

3 participants