From 38b78d6ee7a110850127bff56e9fe1c81ee2c286 Mon Sep 17 00:00:00 2001 From: Petar Heyken Date: Fri, 31 Jan 2025 11:00:34 +0100 Subject: [PATCH 1/2] add test with expected result --- .../api/v31/app14/HelloController.java | 11 +++- .../test/resources/results/3.1.0/app14.json | 60 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/java/test/org/springdoc/api/v31/app14/HelloController.java b/springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/java/test/org/springdoc/api/v31/app14/HelloController.java index 743ad62f6..282a794d0 100644 --- a/springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/java/test/org/springdoc/api/v31/app14/HelloController.java +++ b/springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/java/test/org/springdoc/api/v31/app14/HelloController.java @@ -21,7 +21,7 @@ * * * * * * * * * - * + * */ package test.org.springdoc.api.v31.app14; @@ -31,6 +31,8 @@ import org.springdoc.core.annotations.ParameterObject; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -43,4 +45,11 @@ public ResponseEntity> getAllPets(@ParameterObject Pageable page return null; } + @GetMapping("/test1") + public String getPatientList1(@PageableDefault(size = 100, sort = { "someField", "someoTHER" }, + direction = Sort.Direction.DESC) + @ParameterObject Pageable pageable) { + return "bla"; + } + } diff --git a/springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/resources/results/3.1.0/app14.json b/springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/resources/results/3.1.0/app14.json index a2e119230..471b990a2 100644 --- a/springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/resources/results/3.1.0/app14.json +++ b/springdoc-openapi-tests/springdoc-openapi-data-rest-tests/src/test/resources/results/3.1.0/app14.json @@ -11,6 +11,66 @@ } ], "paths": { + "/test1": { + "get": { + "tags": [ + "hello-controller" + ], + "operationId": "getPatientList1", + "parameters": [ + { + "name": "prefix_pages", + "in": "query", + "description": "One-based page index (1..N)", + "required": false, + "schema": { + "type": "integer", + "default": 1, + "minimum": 0 + } + }, + { + "name": "prefix_sizes", + "in": "query", + "description": "The size of the page to be returned", + "required": false, + "schema": { + "type": "integer", + "default": 100, + "minimum": 1 + } + }, + { + "name": "sorts", + "in": "query", + "description": "Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported.", + "required": false, + "schema": { + "type": "array", + "default": [ + "someField,DESC", + "someoTHER,DESC" + ], + "items": { + "type": "string" + } + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "*/*": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, "/search": { "get": { "tags": [ From 281c896f725542ab2b73d80a45d8e667e9245325 Mon Sep 17 00:00:00 2001 From: Petar Heyken Date: Fri, 31 Jan 2025 11:22:27 +0100 Subject: [PATCH 2/2] fix defaultValue when using @PageableDefault together with one-indexed-parameters --- .../DataRestDelegatingMethodParameterCustomizer.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/customizers/DataRestDelegatingMethodParameterCustomizer.java b/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/customizers/DataRestDelegatingMethodParameterCustomizer.java index 8a8ef92dc..1db18a182 100644 --- a/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/customizers/DataRestDelegatingMethodParameterCustomizer.java +++ b/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/customizers/DataRestDelegatingMethodParameterCustomizer.java @@ -64,6 +64,9 @@ /** * The type Data rest delegating method parameter customizer. + * + * @author bnasslahsen + * @author pheyken */ public class DataRestDelegatingMethodParameterCustomizer implements DelegatingMethodParameterCustomizer { @@ -1131,8 +1134,13 @@ else if (isSpringDataWebPropertiesPresent()) defaultValue = defaultSchemaVal; break; case "page": - if (pageableDefault != null) - defaultValue = String.valueOf(pageableDefault.page()); + if (pageableDefault != null) { + if (isSpringDataWebPropertiesPresent() && optionalSpringDataWebPropertiesProvider.get().getSpringDataWebProperties().getPageable().isOneIndexedParameters()) { + defaultValue = String.valueOf(pageableDefault.page() + 1); + } else { + defaultValue = String.valueOf(pageableDefault.page()); + } + } else if (isSpringDataWebPropertiesPresent() && optionalSpringDataWebPropertiesProvider.get().getSpringDataWebProperties().getPageable().isOneIndexedParameters()) defaultValue = "1"; else