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

fix defaultValue when using @PageableDefault together with one-indexed-parameters #2881

Merged
merged 2 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@

/**
* The type Data rest delegating method parameter customizer.
*
* @author bnasslahsen
* @author pheyken
*/
public class DataRestDelegatingMethodParameterCustomizer implements DelegatingMethodParameterCustomizer {

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* * * *
* * *
* *
*
*
*/

package test.org.springdoc.api.v31.app14;
Expand All @@ -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;
Expand All @@ -43,4 +45,11 @@ public ResponseEntity<List<PersonDTO>> 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";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down