From 56433c25ae4d72e0d7df07b9115bd830f05b0a46 Mon Sep 17 00:00:00 2001 From: Joseph Carmosino Date: Wed, 26 Nov 2025 00:40:34 -0500 Subject: [PATCH 1/3] Fix pagination limit by using correct page[size] parameter #2441 --- app/Http/Controllers/Api/V1/ResultsController.php | 6 +++--- app/OpenApi/Annotations/V1/ResultsAnnotations.php | 4 ++-- app/OpenApi/Schemas/ResultsCollectionSchema.php | 4 ++-- openapi.json | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Api/V1/ResultsController.php b/app/Http/Controllers/Api/V1/ResultsController.php index 9c802fe84..73be765a8 100644 --- a/app/Http/Controllers/Api/V1/ResultsController.php +++ b/app/Http/Controllers/Api/V1/ResultsController.php @@ -28,7 +28,7 @@ public function list(Request $request) ); } $validator = Validator::make($request->all(), [ - 'per_page' => 'integer|min:1|max:500', + 'page.size' => 'integer|min:1|max:500', ]); if ($validator->fails()) { @@ -65,7 +65,7 @@ public function list(Request $request) 'created_at', 'updated_at', ]) - ->jsonPaginate($request->input('per_page', 25)); + ->jsonPaginate(500, 25);; return ResultResource::collection($results); } @@ -115,4 +115,4 @@ public function latest(Request $request) data: new ResultResource($result) ); } -} +} \ No newline at end of file diff --git a/app/OpenApi/Annotations/V1/ResultsAnnotations.php b/app/OpenApi/Annotations/V1/ResultsAnnotations.php index 9bfe6a691..f9b5da455 100644 --- a/app/OpenApi/Annotations/V1/ResultsAnnotations.php +++ b/app/OpenApi/Annotations/V1/ResultsAnnotations.php @@ -19,7 +19,7 @@ class ResultsAnnotations parameters: [ new OA\Parameter(ref: '#/components/parameters/AcceptHeader'), new OA\Parameter( - name: 'per_page', + name: 'per.page', in: 'query', required: false, schema: new OA\Schema(type: 'integer', minimum: 1, maximum: 500, default: 25), @@ -201,4 +201,4 @@ public function show(): void {} ] )] public function latest(): void {} -} +} \ No newline at end of file diff --git a/app/OpenApi/Schemas/ResultsCollectionSchema.php b/app/OpenApi/Schemas/ResultsCollectionSchema.php index 2a4ac55a7..ba5c935a8 100644 --- a/app/OpenApi/Schemas/ResultsCollectionSchema.php +++ b/app/OpenApi/Schemas/ResultsCollectionSchema.php @@ -47,7 +47,7 @@ ) ), new OA\Property(property: 'path', type: 'string'), - new OA\Property(property: 'per_page', type: 'integer'), + new OA\Property(property: 'per.page', type: 'integer'), new OA\Property(property: 'to', type: 'integer'), new OA\Property(property: 'total', type: 'integer'), ], @@ -56,4 +56,4 @@ ], additionalProperties: false )] -class ResultsCollectionSchema {} +class ResultsCollectionSchema {} \ No newline at end of file diff --git a/openapi.json b/openapi.json index ffe15d82d..1717e7ee6 100644 --- a/openapi.json +++ b/openapi.json @@ -21,7 +21,7 @@ "$ref": "#/components/parameters/AcceptHeader" }, { - "name": "per_page", + "name": "per.page", "in": "query", "description": "Number of results per page", "required": false, From eaad87efeab174cf429a166c9204af821f5502d8 Mon Sep 17 00:00:00 2001 From: Joseph Carmosino Date: Wed, 26 Nov 2025 11:47:28 -0500 Subject: [PATCH 2/3] Fixed ResultsController, and linted code. #2441 --- .../Controllers/Api/V1/ResultsController.php | 6 +++--- .../Annotations/V1/ResultsAnnotations.php | 2 +- app/OpenApi/Schemas/ResultsCollectionSchema.php | 2 +- config/json-api-paginate.php | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 config/json-api-paginate.php diff --git a/app/Http/Controllers/Api/V1/ResultsController.php b/app/Http/Controllers/Api/V1/ResultsController.php index 73be765a8..5f462ae3c 100644 --- a/app/Http/Controllers/Api/V1/ResultsController.php +++ b/app/Http/Controllers/Api/V1/ResultsController.php @@ -28,7 +28,7 @@ public function list(Request $request) ); } $validator = Validator::make($request->all(), [ - 'page.size' => 'integer|min:1|max:500', + 'page.size' => 'integer|min:1|max:'.config('json-api-paginate.max_results'), ]); if ($validator->fails()) { @@ -65,7 +65,7 @@ public function list(Request $request) 'created_at', 'updated_at', ]) - ->jsonPaginate(500, 25);; + ->jsonPaginate(); return ResultResource::collection($results); } @@ -115,4 +115,4 @@ public function latest(Request $request) data: new ResultResource($result) ); } -} \ No newline at end of file +} diff --git a/app/OpenApi/Annotations/V1/ResultsAnnotations.php b/app/OpenApi/Annotations/V1/ResultsAnnotations.php index f9b5da455..76b794c90 100644 --- a/app/OpenApi/Annotations/V1/ResultsAnnotations.php +++ b/app/OpenApi/Annotations/V1/ResultsAnnotations.php @@ -201,4 +201,4 @@ public function show(): void {} ] )] public function latest(): void {} -} \ No newline at end of file +} diff --git a/app/OpenApi/Schemas/ResultsCollectionSchema.php b/app/OpenApi/Schemas/ResultsCollectionSchema.php index ba5c935a8..2f8d82c5f 100644 --- a/app/OpenApi/Schemas/ResultsCollectionSchema.php +++ b/app/OpenApi/Schemas/ResultsCollectionSchema.php @@ -56,4 +56,4 @@ ], additionalProperties: false )] -class ResultsCollectionSchema {} \ No newline at end of file +class ResultsCollectionSchema {} diff --git a/config/json-api-paginate.php b/config/json-api-paginate.php new file mode 100644 index 000000000..7c4ac2bed --- /dev/null +++ b/config/json-api-paginate.php @@ -0,0 +1,17 @@ + env('API_MAX_RESULTS', 500), + + /* + * The default number of results that will be returned + * when using the JSON API paginator. + */ + 'default_size' => 25, + +]; \ No newline at end of file From 969f66990d022fd8d4629058e8f31a2189d05a9c Mon Sep 17 00:00:00 2001 From: Joseph Carmosino Date: Wed, 26 Nov 2025 12:46:55 -0500 Subject: [PATCH 3/3] Adds EOF line to config file. --- config/json-api-paginate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/json-api-paginate.php b/config/json-api-paginate.php index 7c4ac2bed..6ff3c2afa 100644 --- a/config/json-api-paginate.php +++ b/config/json-api-paginate.php @@ -14,4 +14,4 @@ */ 'default_size' => 25, -]; \ No newline at end of file +];