Skip to content

fix: to adjust default value and description of the page parameter when enabled spring.data.web.pageable.one-indexed-parameters property. #1754

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

Merged
merged 1 commit into from
Jul 30, 2022
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 @@ -141,7 +141,7 @@ public ParameterIn in() {

@Override
public String description() {
return parameter.description();
return getDescription(parameterName, parameter.description());
}

@Override
Expand Down Expand Up @@ -705,6 +705,20 @@ else if (isSpringDataWebPropertiesPresent())
return name;
}

/**
* Gets description.
*
* @param parameterName the parameter name
* @param originalDescription the original description
* @return the description
*/
private String getDescription(String parameterName, String originalDescription) {
if ("page".equals(parameterName) && isSpringDataWebPropertiesPresent() &&
optionalSpringDataWebPropertiesProvider.get().getSpringDataWebProperties().getPageable().isOneIndexedParameters())
return "One-based page index (1..N)";
return originalDescription;
}

/**
* Gets default value.
*
Expand Down Expand Up @@ -742,6 +756,8 @@ else if (isSpringDataWebPropertiesPresent())
case "page":
if (pageableDefault != null)
defaultValue = String.valueOf(pageableDefault.page());
else if (isSpringDataWebPropertiesPresent() && optionalSpringDataWebPropertiesProvider.get().getSpringDataWebProperties().getPageable().isOneIndexedParameters())
defaultValue = "1";
else
defaultValue = defaultSchemaVal;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
@TestPropertySource(properties = { "spring.data.web.pageable.default-page-size=25",
"spring.data.web.pageable.page-parameter=pages",
"spring.data.web.pageable.size-parameter=sizes",
"spring.data.web.pageable.one-indexed-parameters=true",
"spring.data.web.sort.sort-parameter=sorts" })
@EnableAutoConfiguration(exclude = {
RepositoryRestMvcAutoConfiguration.class, SpringDocDataRestConfiguration.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
{
"name": "pages",
"in": "query",
"description": "Zero-based page index (0..N)",
"description": "One-based page index (1..N)",
"required": false,
"schema": {
"minimum": 0,
"type": "integer",
"default": 0
"default": 1
}
},
{
Expand Down