Skip to content

Commit 80bc5a7

Browse files
project update
1 parent 7c186d8 commit 80bc5a7

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package org.springdoc.config;
22

3+
import org.springframework.context.annotation.Bean;
34
import org.springframework.context.annotation.ComponentScan;
45
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
57

68
@Configuration
79
@ComponentScan(basePackages = {"org.springdoc"})
810
public class SpringDocConfiguration {
911

12+
@Bean
13+
LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer() {
14+
return new LocalVariableTableParameterNameDiscoverer();
15+
}
1016
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.apache.commons.lang3.ClassUtils;
1818
import org.apache.commons.lang3.StringUtils;
1919
import org.apache.commons.lang3.reflect.MethodUtils;
20+
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
2021
import org.springframework.core.annotation.AnnotationUtils;
2122
import org.springframework.web.method.HandlerMethod;
2223

@@ -30,6 +31,12 @@
3031
@SuppressWarnings("rawtypes")
3132
public abstract class AbstractParameterBuilder {
3233

34+
protected LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer;
35+
36+
public AbstractParameterBuilder(LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer) {
37+
this.localSpringDocParameterNameDiscoverer = localSpringDocParameterNameDiscoverer;
38+
}
39+
3340
Parameter mergeParameter(List<Parameter> existingParamDoc, Parameter paramCalcul) {
3441
Parameter result = paramCalcul;
3542
if (paramCalcul != null && paramCalcul.getName() != null) {
@@ -168,6 +175,10 @@ Schema calculateSchema(Components components, java.lang.reflect.Parameter parame
168175
return schemaN;
169176
}
170177

178+
public LocalVariableTableParameterNameDiscoverer getLocalSpringDocParameterNameDiscoverer() {
179+
return localSpringDocParameterNameDiscoverer;
180+
}
181+
171182
protected abstract Schema calculateSchemaFromParameterizedType(Components components, Type returnType, JsonView jsonView);
172183

173184
private Schema extractFileSchema(String paramName, RequestBodyInfo requestBodyInfo) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.swagger.v3.oas.models.parameters.Parameter;
88
import org.apache.commons.lang3.StringUtils;
99
import org.springdoc.core.RequestInfo.ParameterType;
10+
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
1011
import org.springframework.core.annotation.AnnotatedElementUtils;
1112
import org.springframework.util.CollectionUtils;
1213
import org.springframework.web.bind.annotation.*;
@@ -50,8 +51,12 @@ public Operation build(Components components, HandlerMethod handlerMethod, Reque
5051

5152
operation.setOperationId(operationId);
5253
// requests
54+
LocalVariableTableParameterNameDiscoverer d = parameterBuilder.getLocalSpringDocParameterNameDiscoverer();
55+
String[] pNames = d.getParameterNames(handlerMethod.getMethod());
5356
java.lang.reflect.Parameter[] parameters = handlerMethod.getMethod().getParameters();
54-
String[] pNames = Arrays.stream(parameters).map(java.lang.reflect.Parameter::getName).toArray(String[]::new);
57+
if (pNames == null) {
58+
pNames = Arrays.stream(parameters).map(java.lang.reflect.Parameter::getName).toArray(String[]::new);
59+
}
5560
RequestBodyInfo requestBodyInfo = new RequestBodyInfo(methodAttributes);
5661
List<Parameter> operationParameters = (operation.getParameters() != null) ? operation.getParameters()
5762
: new ArrayList<>();

springdoc-openapi-webflux-core/src/main/java/org/springdoc/core/ParameterBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.databind.JavaType;
55
import io.swagger.v3.oas.models.Components;
66
import io.swagger.v3.oas.models.media.Schema;
7+
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
78
import org.springframework.http.codec.multipart.FilePart;
89
import org.springframework.stereotype.Component;
910
import org.springframework.web.multipart.MultipartFile;
@@ -17,6 +18,10 @@
1718
@Component
1819
public class ParameterBuilder extends AbstractParameterBuilder {
1920

21+
public ParameterBuilder(LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer) {
22+
super(localSpringDocParameterNameDiscoverer);
23+
}
24+
2025
@Override
2126
protected Schema calculateSchemaFromParameterizedType(Components components, Type paramType, JsonView jsonView) {
2227
Schema schemaN;

springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/ParameterBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.databind.JavaType;
55
import io.swagger.v3.oas.models.Components;
66
import io.swagger.v3.oas.models.media.Schema;
7+
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
78
import org.springframework.stereotype.Component;
89
import org.springframework.web.multipart.MultipartFile;
910

@@ -14,6 +15,10 @@
1415
@Component
1516
public class ParameterBuilder extends AbstractParameterBuilder {
1617

18+
public ParameterBuilder(LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer) {
19+
super(localSpringDocParameterNameDiscoverer);
20+
}
21+
1722
@Override
1823
protected Schema calculateSchemaFromParameterizedType(Components components, Type paramType, JsonView jsonView) {
1924
return SpringDocAnnotationsUtils.extractSchema(components, paramType, jsonView);

0 commit comments

Comments
 (0)