Skip to content

Commit 9b0056a

Browse files
author
Marcin Zarebski
committed
Get fields of superclass for parameter objects
1 parent c46eb03 commit 9b0056a

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/DelegatingMethodParameter.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static MethodParameter[] customize(String[] pNames, MethodParameter[] par
5050
MethodParameter p = parameters[i];
5151
if (p.hasParameterAnnotation(ParameterObject.class)) {
5252
Class<?> paramClass = AdditionalModelsConverter.getReplacement(p.getParameterType());
53-
Stream.of(paramClass.getDeclaredFields())
53+
allFieldsOf(paramClass).stream()
5454
.map(f -> fromGetterOfField(paramClass, f))
5555
.filter(Objects::nonNull)
5656
.forEach(explodedParameters::add);
@@ -186,4 +186,13 @@ private class NullableFieldClass {
186186
@Nullable
187187
private String nullableField;
188188
}
189+
190+
private static List<Field> allFieldsOf(Class<?> clazz) {
191+
List<Field> fields = new ArrayList<>();
192+
do {
193+
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
194+
clazz = clazz.getSuperclass();
195+
} while (clazz != null);
196+
return fields;
197+
}
189198
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package test.org.springdoc.api.app102;
2+
3+
import io.swagger.v3.oas.annotations.Parameter;
4+
5+
public class InheritedRequestParams extends RequestParams {
6+
@Parameter(description = "parameter from child of RequestParams")
7+
private String childParam;
8+
9+
public String getChildParam() {
10+
return childParam;
11+
}
12+
13+
public void setChildParam(String childParam) {
14+
this.childParam = childParam;
15+
}
16+
}

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app102/TestController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
@RestController
1111
public class TestController {
1212
@GetMapping("test")
13-
public void getTest(@RequestParam @Nullable String param, @ParameterObject RequestParams requestParams) {
13+
public void getTest(@RequestParam @Nullable String param, @ParameterObject InheritedRequestParams requestParams) {
1414
}
1515
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
"type": "string"
2727
}
2828
},
29+
{
30+
"name": "childParam",
31+
"in": "query",
32+
"description": "parameter from child of RequestParams",
33+
"required": false,
34+
"schema": {
35+
"type": "string"
36+
}
37+
},
2938
{
3039
"name": "stringParam",
3140
"in": "query",

0 commit comments

Comments
 (0)