Skip to content

Commit

Permalink
Merge pull request #1700 from daniel-shuy/spring-data-pageabledefault…
Browse files Browse the repository at this point in the history
…-value

fix: Support PageableDefault#value()
  • Loading branch information
bnasslahsen committed Jun 8, 2022
2 parents ff9c81d + 6ff5d42 commit f5208eb
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 2 deletions.
Expand Up @@ -26,6 +26,7 @@
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -716,8 +717,21 @@ private String getDefaultValue(String parameterName, PageableDefault pageableDef
String defaultValue = null;
switch (parameterName) {
case "size":
if (pageableDefault != null)
defaultValue = String.valueOf(pageableDefault.size());
if (pageableDefault != null) {
// "size" is aliased as "value"
int size = pageableDefault.size();
Object defaultSize;
try {
defaultSize = PageableDefault.class.getMethod("size").getDefaultValue();
} catch (NoSuchMethodException e) {
LOGGER.warn(e.getMessage());
defaultSize = null;
}
if (Objects.deepEquals(size, defaultSize)) {
size = pageableDefault.value();
}
defaultValue = String.valueOf(size);
}
else if (isRepositoryRestConfigurationPresent())
defaultValue = String.valueOf(optionalRepositoryRestConfigurationProvider.get().getRepositoryRestConfiguration().getDefaultPageSize());
else if (isSpringDataWebPropertiesPresent())
Expand Down
Expand Up @@ -57,4 +57,10 @@ public String getPatientList3(@PageableDefault(size = 100)
@ParameterObject Pageable pageable) {
return "bla";
}

@GetMapping("/test4")
public String getPatientList4(@PageableDefault(100)
@ParameterObject Pageable pageable) {
return "bla";
}
}
56 changes: 56 additions & 0 deletions springdoc-openapi-data-rest/src/test/resources/results/app13.json
Expand Up @@ -11,6 +11,62 @@
}
],
"paths": {
"/test4": {
"get": {
"tags": [
"hello-controller"
],
"operationId": "getPatientList4",
"parameters": [
{
"name": "page",
"in": "query",
"description": "Zero-based page index (0..N)",
"required": false,
"schema": {
"minimum": 0,
"type": "integer",
"default": 0
}
},
{
"name": "size",
"in": "query",
"description": "The size of the page to be returned",
"required": false,
"schema": {
"minimum": 1,
"type": "integer",
"default": 100
}
},
{
"name": "sort",
"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",
"items": {
"type": "string"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/hal+json": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/test3": {
"get": {
"tags": [
Expand Down
Expand Up @@ -62,4 +62,10 @@ public String getPatientList3(@PageableDefault(size = 100)
@ParameterObject Pageable pageable) {
return "bla";
}

@GetMapping("/test4")
public String getPatientList4(@PageableDefault(100)
@ParameterObject Pageable pageable) {
return "bla";
}
}
Expand Up @@ -11,6 +11,62 @@
}
],
"paths": {
"/test4": {
"get": {
"tags": [
"hello-controller"
],
"operationId": "getPatientList4",
"parameters": [
{
"name": "page",
"in": "query",
"description": "Zero-based page index (0..N)",
"required": false,
"schema": {
"minimum": 0,
"type": "integer",
"default": 0
}
},
{
"name": "size",
"in": "query",
"description": "The size of the page to be returned",
"required": false,
"schema": {
"minimum": 1,
"type": "integer",
"default": 100
}
},
{
"name": "sort",
"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",
"items": {
"type": "string"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/test3": {
"get": {
"tags": [
Expand Down

0 comments on commit f5208eb

Please sign in to comment.