Skip to content

Commit 5192aae

Browse files
committed
springdoc-openapi-javadoc doesn't work with @ParameterObject. Fixes #1324.
1 parent 7c96034 commit 5192aae

File tree

1,222 files changed

+33908
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,222 files changed

+33908
-11
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
import org.springframework.web.method.HandlerMethod;
107107

108108
import static org.springdoc.core.Constants.ACTUATOR_DEFAULT_GROUP;
109+
import static org.springdoc.core.Constants.DOT;
109110
import static org.springdoc.core.Constants.LINKS_SCHEMA_CUSTOMISER;
110111
import static org.springdoc.core.Constants.OPERATION_ATTRIBUTE;
111112
import static org.springdoc.core.Constants.SPRING_MVC_SERVLET_PATH;
@@ -667,10 +668,10 @@ protected boolean isPackageToScan(Package aPackage) {
667668
}
668669
boolean include = CollectionUtils.isEmpty(packagesToScan)
669670
|| packagesToScan.stream().anyMatch(pack -> packageName.equals(pack)
670-
|| packageName.startsWith(pack + "."));
671+
|| packageName.startsWith(pack + DOT));
671672
boolean exclude = !CollectionUtils.isEmpty(packagesToExclude)
672673
&& (packagesToExclude.stream().anyMatch(pack -> packageName.equals(pack)
673-
|| packageName.startsWith(pack + ".")));
674+
|| packageName.startsWith(pack + DOT)));
674675

675676
return include && !exclude;
676677
}

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package org.springdoc.core;
2222

2323
import java.lang.annotation.Annotation;
24+
import java.lang.reflect.Field;
2425
import java.lang.reflect.Method;
2526
import java.math.BigDecimal;
2627
import java.util.ArrayList;
@@ -58,6 +59,7 @@
5859
import org.apache.commons.lang3.ArrayUtils;
5960
import org.apache.commons.lang3.ClassUtils;
6061
import org.apache.commons.lang3.StringUtils;
62+
import org.apache.commons.lang3.reflect.FieldUtils;
6163
import org.springdoc.core.customizers.ParameterCustomizer;
6264

6365
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
@@ -78,6 +80,7 @@
7880
import org.springframework.web.method.HandlerMethod;
7981
import org.springframework.web.util.UriComponentsBuilder;
8082

83+
import static org.springdoc.core.Constants.DOT;
8184
import static org.springdoc.core.Constants.OPENAPI_ARRAY_TYPE;
8285
import static org.springdoc.core.Constants.OPENAPI_STRING_TYPE;
8386
import static org.springdoc.core.Constants.QUERY_PARAM;
@@ -267,7 +270,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
267270
if (isValidParameter(parameter)) {
268271
// Add param javadoc
269272
if (StringUtils.isBlank(parameter.getDescription()) && javadocProvider != null) {
270-
String paramJavadocDescription = javadocProvider.getParamJavadoc(handlerMethod.getMethod(), pName);
273+
String paramJavadocDescription = getParamJavadoc(javadocProvider, methodParameter, pName);
271274
if (!StringUtils.isBlank(paramJavadocDescription)) {
272275
parameter.setDescription(paramJavadocDescription);
273276
}
@@ -281,7 +284,7 @@ else if (!RequestMethod.GET.equals(requestMethod)) {
281284
parameterInfo, requestBodyInfo);
282285
// Add requestBody javadoc
283286
if (StringUtils.isBlank(requestBodyInfo.getRequestBody().getDescription()) && javadocProvider != null) {
284-
String paramJavadocDescription = javadocProvider.getParamJavadoc(handlerMethod.getMethod(), pName);
287+
String paramJavadocDescription = getParamJavadoc(javadocProvider, methodParameter, pName);
285288
if (!StringUtils.isBlank(paramJavadocDescription)) {
286289
requestBodyInfo.getRequestBody().setDescription(paramJavadocDescription);
287290
}
@@ -671,4 +674,29 @@ private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo pa
671674
|| (!ClassUtils.isPrimitiveOrWrapper(methodParameter.getParameter().getType()) && (!ArrayUtils.isEmpty(methodParameter.getParameterAnnotations()) || length == 1)));
672675
}
673676

677+
/**
678+
* Gets param javadoc.
679+
*
680+
* @param javadocProvider the javadoc provider
681+
* @param methodParameter the method parameter
682+
* @param pName the p name
683+
* @return the param javadoc
684+
*/
685+
private String getParamJavadoc(JavadocProvider javadocProvider, MethodParameter methodParameter, String pName) {
686+
DelegatingMethodParameter delegatingMethodParameter = (DelegatingMethodParameter) methodParameter;
687+
final String paramJavadocDescription;
688+
if (delegatingMethodParameter.isParameterObject()) {
689+
String fieldName;
690+
if (pName.contains(DOT))
691+
fieldName = StringUtils.substringAfter(pName, DOT);
692+
else
693+
fieldName = pName;
694+
Field field = FieldUtils.getDeclaredField(((DelegatingMethodParameter) methodParameter).getExecutable().getDeclaringClass(), fieldName, true);
695+
paramJavadocDescription = javadocProvider.getFieldJavadoc(field);
696+
}
697+
else
698+
paramJavadocDescription = javadocProvider.getParamJavadoc(methodParameter.getMethod(), pName);
699+
return paramJavadocDescription;
700+
}
701+
674702
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ public final class Constants {
6565
*/
6666
public static final String YAML = "yaml";
6767

68+
/**
69+
* The constant DOT.
70+
*/
71+
public static final String DOT = ".";
72+
6873
/**
6974
* The constant DEFAULT_API_DOCS_URL_YAML.
7075
*/
71-
public static final String DEFAULT_API_DOCS_URL_YAML = API_DOCS_URL + "." + YAML;
76+
public static final String DEFAULT_API_DOCS_URL_YAML = API_DOCS_URL + DOT + YAML;
7277

7378
/**
7479
* The constant SPRINGDOC_ENABLED.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949

5050
import org.springframework.core.MethodParameter;
5151

52+
import static org.springdoc.core.Constants.DOT;
53+
5254
/**
5355
* The type Method parameter pojo extractor.
5456
* @author bnasslahsen
@@ -129,7 +131,7 @@ private static Stream<MethodParameter> fromGetterOfField(Class<?> paramClass, Fi
129131
else if (field.getGenericType() instanceof TypeVariable<?>)
130132
return extractTypeParameter(paramClass, (TypeVariable<?>) field.getGenericType(), field, fieldNamePrefix);
131133
else
132-
return extractFrom(field.getType(), fieldNamePrefix + field.getName() + ".");
134+
return extractFrom(field.getType(), fieldNamePrefix + field.getName() + DOT);
133135
}
134136

135137
/**

springdoc-openapi-javadoc/src/test/java/test/org/springdoc/api/app121/InheritedRequestParams.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
import javax.validation.constraints.NotBlank;
44

5-
import io.swagger.v3.oas.annotations.Parameter;
6-
75
/**
86
* The type Inherited request params.
97
*/
108
public class InheritedRequestParams extends RequestParams {
119

1210
/**
13-
* The Child param.
11+
* parameter from child of RequestParams
1412
*/
15-
@Parameter(description = "parameter from child of RequestParams")
1613
@NotBlank
1714
private String childParam;
1815

springdoc-openapi-javadoc/src/test/resources/results/app102.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
{
5050
"name": "stringParam1",
5151
"in": "query",
52+
"description": "The String param 1.",
5253
"required": false,
5354
"deprecated": true,
5455
"schema": {
@@ -77,6 +78,7 @@
7778
{
7879
"name": "intParam2",
7980
"in": "query",
81+
"description": "The Int param 2.",
8082
"required": false,
8183
"schema": {
8284
"type": "string"
@@ -85,6 +87,7 @@
8587
{
8688
"name": "intParam3",
8789
"in": "query",
90+
"description": "The Int param 3.",
8891
"required": false,
8992
"schema": {
9093
"type": "string"
@@ -93,6 +96,7 @@
9396
{
9497
"name": "nested.param1",
9598
"in": "query",
99+
"description": "The Param 1.",
96100
"required": false,
97101
"schema": {
98102
"type": "string"
@@ -101,6 +105,7 @@
101105
{
102106
"name": "nested.param2",
103107
"in": "query",
108+
"description": "The Param 2.",
104109
"required": false,
105110
"schema": {
106111
"type": "integer"
@@ -109,6 +114,7 @@
109114
{
110115
"name": "nestedList",
111116
"in": "query",
117+
"description": "The Nested list.",
112118
"required": false,
113119
"schema": {
114120
"type": "array",

springdoc-openapi-javadoc/src/test/resources/results/app121.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
{
5050
"name": "stringParam1",
5151
"in": "query",
52+
"description": "The String param 1.",
5253
"required": false,
5354
"deprecated": true,
5455
"schema": {
@@ -77,6 +78,7 @@
7778
{
7879
"name": "intParam2",
7980
"in": "query",
81+
"description": "The Int param 2.",
8082
"required": false,
8183
"schema": {
8284
"type": "string"
@@ -85,6 +87,7 @@
8587
{
8688
"name": "intParam3",
8789
"in": "query",
90+
"description": "The Int param 3.",
8891
"required": false,
8992
"schema": {
9093
"type": "string"
@@ -93,6 +96,7 @@
9396
{
9497
"name": "nested.param1",
9598
"in": "query",
99+
"description": "The Param 1.",
96100
"required": false,
97101
"schema": {
98102
"type": "string"
@@ -101,6 +105,7 @@
101105
{
102106
"name": "nested.param2",
103107
"in": "query",
108+
"description": "The Param 2.",
104109
"required": false,
105110
"schema": {
106111
"type": "integer"
@@ -109,6 +114,7 @@
109114
{
110115
"name": "nestedList",
111116
"in": "query",
117+
"description": "The Nested list.",
112118
"required": false,
113119
"schema": {
114120
"type": "array",
@@ -192,7 +198,7 @@
192198
},
193199
"childParam": {
194200
"type": "string",
195-
"description": "The Child param."
201+
"description": "parameter from child of RequestParams"
196202
}
197203
}
198204
}

springdoc-openapi-javadoc/src/test/resources/results/app155.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
{
2323
"name": "primitiveConcreteField",
2424
"in": "query",
25+
"description": "The Primitive concrete field.",
2526
"required": false,
2627
"schema": {
2728
"type": "integer",
@@ -31,6 +32,7 @@
3132
{
3233
"name": "primitiveBaseField",
3334
"in": "query",
35+
"description": "The Primitive base field.",
3436
"required": false,
3537
"schema": {
3638
"type": "integer",
@@ -40,6 +42,7 @@
4042
{
4143
"name": "genericField",
4244
"in": "query",
45+
"description": "The Generic field.",
4346
"required": false,
4447
"schema": {
4548
"type": "string",
@@ -75,6 +78,7 @@
7578
{
7679
"name": "primitiveConcreteField",
7780
"in": "query",
81+
"description": "The Primitive concrete field.",
7882
"required": false,
7983
"schema": {
8084
"type": "integer",
@@ -84,6 +88,7 @@
8488
{
8589
"name": "primitiveBaseField",
8690
"in": "query",
91+
"description": "The Primitive base field.",
8792
"required": false,
8893
"schema": {
8994
"type": "integer",
@@ -93,6 +98,7 @@
9398
{
9499
"name": "genericField",
95100
"in": "query",
101+
"description": "The Generic field.",
96102
"required": false,
97103
"schema": {
98104
"type": "integer",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<!-- NewPage -->
3+
<html lang="fr">
4+
<head>
5+
<!-- Generated by javadoc (1.8.0_275) on Tue Oct 19 12:24:25 CEST 2021 -->
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<title>All Classes (springdoc-openapi-javadoc 1.5.12-SNAPSHOT API)</title>
8+
<meta name="date" content="2021-10-19">
9+
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
10+
<script type="text/javascript" src="script.js"></script>
11+
</head>
12+
<body>
13+
<h1 class="bar">All&nbsp;Classes</h1>
14+
<div class="indexContainer">
15+
<ul>
16+
<li><a href="org/springdoc/openapi/javadoc/JavadocPropertyCustomizer.html" title="class in org.springdoc.openapi.javadoc" target="classFrame">JavadocPropertyCustomizer</a></li>
17+
<li><a href="org/springdoc/openapi/javadoc/SpringDocJavadocConfiguration.html" title="class in org.springdoc.openapi.javadoc" target="classFrame">SpringDocJavadocConfiguration</a></li>
18+
<li><a href="org/springdoc/openapi/javadoc/SpringDocJavadocProvider.html" title="class in org.springdoc.openapi.javadoc" target="classFrame">SpringDocJavadocProvider</a></li>
19+
</ul>
20+
</div>
21+
</body>
22+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<!-- NewPage -->
3+
<html lang="fr">
4+
<head>
5+
<!-- Generated by javadoc (1.8.0_275) on Tue Oct 19 12:24:25 CEST 2021 -->
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<title>All Classes (springdoc-openapi-javadoc 1.5.12-SNAPSHOT API)</title>
8+
<meta name="date" content="2021-10-19">
9+
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
10+
<script type="text/javascript" src="script.js"></script>
11+
</head>
12+
<body>
13+
<h1 class="bar">All&nbsp;Classes</h1>
14+
<div class="indexContainer">
15+
<ul>
16+
<li><a href="org/springdoc/openapi/javadoc/JavadocPropertyCustomizer.html" title="class in org.springdoc.openapi.javadoc">JavadocPropertyCustomizer</a></li>
17+
<li><a href="org/springdoc/openapi/javadoc/SpringDocJavadocConfiguration.html" title="class in org.springdoc.openapi.javadoc">SpringDocJavadocConfiguration</a></li>
18+
<li><a href="org/springdoc/openapi/javadoc/SpringDocJavadocProvider.html" title="class in org.springdoc.openapi.javadoc">SpringDocJavadocProvider</a></li>
19+
</ul>
20+
</div>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)