Skip to content

Commit 6ff5d42

Browse files
committed
Support PageableDefault#value()
PageableDefault#value() is an alias for PageableDefault#size()
1 parent ff9c81d commit 6ff5d42

File tree

5 files changed

+140
-2
lines changed

5 files changed

+140
-2
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/customizers/DataRestDelegatingMethodParameterCustomizer.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.lang.reflect.Field;
2727
import java.util.ArrayList;
2828
import java.util.List;
29+
import java.util.Objects;
2930
import java.util.Optional;
3031

3132
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -716,8 +717,21 @@ private String getDefaultValue(String parameterName, PageableDefault pageableDef
716717
String defaultValue = null;
717718
switch (parameterName) {
718719
case "size":
719-
if (pageableDefault != null)
720-
defaultValue = String.valueOf(pageableDefault.size());
720+
if (pageableDefault != null) {
721+
// "size" is aliased as "value"
722+
int size = pageableDefault.size();
723+
Object defaultSize;
724+
try {
725+
defaultSize = PageableDefault.class.getMethod("size").getDefaultValue();
726+
} catch (NoSuchMethodException e) {
727+
LOGGER.warn(e.getMessage());
728+
defaultSize = null;
729+
}
730+
if (Objects.deepEquals(size, defaultSize)) {
731+
size = pageableDefault.value();
732+
}
733+
defaultValue = String.valueOf(size);
734+
}
721735
else if (isRepositoryRestConfigurationPresent())
722736
defaultValue = String.valueOf(optionalRepositoryRestConfigurationProvider.get().getRepositoryRestConfiguration().getDefaultPageSize());
723737
else if (isSpringDataWebPropertiesPresent())

springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app13/HelloController.java

+6
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,10 @@ public String getPatientList3(@PageableDefault(size = 100)
5757
@ParameterObject Pageable pageable) {
5858
return "bla";
5959
}
60+
61+
@GetMapping("/test4")
62+
public String getPatientList4(@PageableDefault(100)
63+
@ParameterObject Pageable pageable) {
64+
return "bla";
65+
}
6066
}

springdoc-openapi-data-rest/src/test/resources/results/app13.json

+56
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,62 @@
1111
}
1212
],
1313
"paths": {
14+
"/test4": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "getPatientList4",
20+
"parameters": [
21+
{
22+
"name": "page",
23+
"in": "query",
24+
"description": "Zero-based page index (0..N)",
25+
"required": false,
26+
"schema": {
27+
"minimum": 0,
28+
"type": "integer",
29+
"default": 0
30+
}
31+
},
32+
{
33+
"name": "size",
34+
"in": "query",
35+
"description": "The size of the page to be returned",
36+
"required": false,
37+
"schema": {
38+
"minimum": 1,
39+
"type": "integer",
40+
"default": 100
41+
}
42+
},
43+
{
44+
"name": "sort",
45+
"in": "query",
46+
"description": "Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported.",
47+
"required": false,
48+
"schema": {
49+
"type": "array",
50+
"items": {
51+
"type": "string"
52+
}
53+
}
54+
}
55+
],
56+
"responses": {
57+
"200": {
58+
"description": "OK",
59+
"content": {
60+
"application/hal+json": {
61+
"schema": {
62+
"type": "string"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
},
1470
"/test3": {
1571
"get": {
1672
"tags": [

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/v30/app176/HelloController.java

+6
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,10 @@ public String getPatientList3(@PageableDefault(size = 100)
6262
@ParameterObject Pageable pageable) {
6363
return "bla";
6464
}
65+
66+
@GetMapping("/test4")
67+
public String getPatientList4(@PageableDefault(100)
68+
@ParameterObject Pageable pageable) {
69+
return "bla";
70+
}
6571
}

springdoc-openapi-webmvc-core/src/test/resources/results/3.0.1/app176.json

+56
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,62 @@
1111
}
1212
],
1313
"paths": {
14+
"/test4": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "getPatientList4",
20+
"parameters": [
21+
{
22+
"name": "page",
23+
"in": "query",
24+
"description": "Zero-based page index (0..N)",
25+
"required": false,
26+
"schema": {
27+
"minimum": 0,
28+
"type": "integer",
29+
"default": 0
30+
}
31+
},
32+
{
33+
"name": "size",
34+
"in": "query",
35+
"description": "The size of the page to be returned",
36+
"required": false,
37+
"schema": {
38+
"minimum": 1,
39+
"type": "integer",
40+
"default": 100
41+
}
42+
},
43+
{
44+
"name": "sort",
45+
"in": "query",
46+
"description": "Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported.",
47+
"required": false,
48+
"schema": {
49+
"type": "array",
50+
"items": {
51+
"type": "string"
52+
}
53+
}
54+
}
55+
],
56+
"responses": {
57+
"200": {
58+
"description": "OK",
59+
"content": {
60+
"*/*": {
61+
"schema": {
62+
"type": "string"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
},
1470
"/test3": {
1571
"get": {
1672
"tags": [

0 commit comments

Comments
 (0)