Repository: springdoc/springdoc-openapi
Pull request #596 (2020-04-22 08:31:28)

Get fields of superclass for parameter objects


Patch:
diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/DelegatingMethodParameter.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/DelegatingMethodParameter.java
index 2aade0e87..dbdd1a975 100644
--- a/springdoc-openapi-common/src/main/java/org/springdoc/core/DelegatingMethodParameter.java
+++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/DelegatingMethodParameter.java
@@ -50,7 +50,7 @@ class DelegatingMethodParameter extends MethodParameter {
 			MethodParameter p = parameters[i];
 			if (p.hasParameterAnnotation(ParameterObject.class)) {
 				Class<?> paramClass = AdditionalModelsConverter.getReplacement(p.getParameterType());
-				Stream.of(paramClass.getDeclaredFields())
+				allFieldsOf(paramClass).stream()
 						.map(f -> fromGetterOfField(paramClass, f))
 						.filter(Objects::nonNull)
 						.forEach(explodedParameters::add);
@@ -186,4 +186,13 @@ class DelegatingMethodParameter extends MethodParameter {
 		@Nullable
 		private String nullableField;
 	}
+
+	private static List<Field> allFieldsOf(Class<?> clazz) {
+		List<Field> fields = new ArrayList<>();
+		do {
+			fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
+			clazz = clazz.getSuperclass();
+		} while (clazz != null);
+		return fields;
+	}
 }


Test patch:
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app102/InheritedRequestParams.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app102/InheritedRequestParams.java
new file mode 100644
index 000000000..cf9554eb0
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app102/InheritedRequestParams.java
@@ -0,0 +1,16 @@
+package test.org.springdoc.api.app102;
+
+import io.swagger.v3.oas.annotations.Parameter;
+
+public class InheritedRequestParams extends RequestParams {
+	@Parameter(description = "parameter from child of RequestParams")
+	private String childParam;
+
+	public String getChildParam() {
+		return childParam;
+	}
+
+	public void setChildParam(String childParam) {
+		this.childParam = childParam;
+	}
+}
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app102/TestController.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app102/TestController.java
index e4f090d17..091e0b1b4 100644
--- a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app102/TestController.java
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app102/TestController.java
@@ -10,6 +10,6 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 public class TestController {
 	@GetMapping("test")
-	public void getTest(@RequestParam @Nullable String param, @ParameterObject RequestParams requestParams) {
+	public void getTest(@RequestParam @Nullable String param, @ParameterObject InheritedRequestParams requestParams) {
 	}
 }
diff --git a/springdoc-openapi-webmvc-core/src/test/resources/results/app102.json b/springdoc-openapi-webmvc-core/src/test/resources/results/app102.json
index e82722581..88dfe6b9b 100644
--- a/springdoc-openapi-webmvc-core/src/test/resources/results/app102.json
+++ b/springdoc-openapi-webmvc-core/src/test/resources/results/app102.json
@@ -26,6 +26,15 @@
               "type": "string"
             }
           },
+          {
+            "name": "childParam",
+            "in": "query",
+            "description": "parameter from child of RequestParams",
+            "required": false,
+            "schema": {
+              "type": "string"
+            }
+          },
           {
             "name": "stringParam",
             "in": "query",