Skip to content

Commit 86ea672

Browse files
Fix pagination limit by using correct page[size] parameter alexjustesen#2441 (alexjustesen#2442)
1 parent d1d7b9e commit 86ea672

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

app/Http/Controllers/Api/V1/ResultsController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function list(Request $request)
2828
);
2929
}
3030
$validator = Validator::make($request->all(), [
31-
'per_page' => 'integer|min:1|max:500',
31+
'page.size' => 'integer|min:1|max:'.config('json-api-paginate.max_results'),
3232
]);
3333

3434
if ($validator->fails()) {
@@ -65,7 +65,7 @@ public function list(Request $request)
6565
'created_at',
6666
'updated_at',
6767
])
68-
->jsonPaginate($request->input('per_page', 25));
68+
->jsonPaginate();
6969

7070
return ResultResource::collection($results);
7171
}

app/OpenApi/Annotations/V1/ResultsAnnotations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ResultsAnnotations
1919
parameters: [
2020
new OA\Parameter(ref: '#/components/parameters/AcceptHeader'),
2121
new OA\Parameter(
22-
name: 'per_page',
22+
name: 'per.page',
2323
in: 'query',
2424
required: false,
2525
schema: new OA\Schema(type: 'integer', minimum: 1, maximum: 500, default: 25),

app/OpenApi/Schemas/ResultsCollectionSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
)
4848
),
4949
new OA\Property(property: 'path', type: 'string'),
50-
new OA\Property(property: 'per_page', type: 'integer'),
50+
new OA\Property(property: 'per.page', type: 'integer'),
5151
new OA\Property(property: 'to', type: 'integer'),
5252
new OA\Property(property: 'total', type: 'integer'),
5353
],

config/json-api-paginate.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
* The maximum number of results that will be returned
7+
* when using the JSON API paginator.
8+
*/
9+
'max_results' => env('API_MAX_RESULTS', 500),
10+
11+
/*
12+
* The default number of results that will be returned
13+
* when using the JSON API paginator.
14+
*/
15+
'default_size' => 25,
16+
17+
];

openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"$ref": "#/components/parameters/AcceptHeader"
2222
},
2323
{
24-
"name": "per_page",
24+
"name": "per.page",
2525
"in": "query",
2626
"description": "Number of results per page",
2727
"required": false,

0 commit comments

Comments
 (0)