Skip to content

Commit ffc7ad2

Browse files
committed
clear logic for flat parameter object
1 parent d4f99ac commit ffc7ad2

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* *
44
* * *
55
* * * *
6-
* * * * * Copyright 2019-2022 the original author or authors.
6+
* * * * * Copyright 2019-2023 the original author or authors.
77
* * * * *
88
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
99
* * * * * you may not use this file except in compliance with the License.
@@ -124,31 +124,16 @@ public static MethodParameter[] customize(String[] pNames, MethodParameter[] par
124124
MethodParameter p = parameters[i];
125125
Class<?> paramClass = AdditionalModelsConverter.getParameterObjectReplacement(p.getParameterType());
126126

127-
if (!MethodParameterPojoExtractor.isSimpleType(paramClass) && (p.hasParameterAnnotation(ParameterObject.class) || AnnotatedElementUtils.isAnnotated(paramClass, ParameterObject.class))) {
127+
boolean hasFlatAnnotation = p.hasParameterAnnotation(ParameterObject.class) || AnnotatedElementUtils.isAnnotated(paramClass, ParameterObject.class);
128+
boolean hasNotFlatAnnotation = Arrays.stream(p.getParameterAnnotations())
129+
.anyMatch(annotation -> Arrays.asList(RequestBody.class, RequestPart.class).contains(annotation.annotationType()));
130+
if (!MethodParameterPojoExtractor.isSimpleType(paramClass)
131+
&& (hasFlatAnnotation || (defaultFlatParamObject && !hasNotFlatAnnotation && !AbstractRequestService.isRequestTypeToIgnore(paramClass)))) {
128132
MethodParameterPojoExtractor.extractFrom(paramClass).forEach(methodParameter -> {
129133
optionalDelegatingMethodParameterCustomizer.ifPresent(customizer -> customizer.customize(p, methodParameter));
130134
explodedParameters.add(methodParameter);
131135
});
132136
}
133-
else if (defaultFlatParamObject) {
134-
boolean isSimpleType = MethodParameterPojoExtractor.isSimpleType(paramClass);
135-
List<Annotation> annotations = Arrays.stream(p.getParameterAnnotations())
136-
.filter(annotation -> Arrays.asList(RequestBody.class, RequestPart.class).contains(annotation.annotationType()))
137-
.toList();
138-
boolean hasAnnotation = !annotations.isEmpty();
139-
boolean shouldFlat = !isSimpleType && !hasAnnotation;
140-
if (shouldFlat && !AbstractRequestService.isRequestTypeToIgnore(paramClass)) {
141-
MethodParameterPojoExtractor.extractFrom(paramClass).forEach(methodParameter -> {
142-
optionalDelegatingMethodParameterCustomizer
143-
.ifPresent(customizer -> customizer.customize(p, methodParameter));
144-
explodedParameters.add(methodParameter);
145-
});
146-
}
147-
else {
148-
String name = pNames != null ? pNames[i] : p.getParameterName();
149-
explodedParameters.add(new DelegatingMethodParameter(p, name, null, false, false));
150-
}
151-
}
152137
else {
153138
String name = pNames != null ? pNames[i] : p.getParameterName();
154139
explodedParameters.add(new DelegatingMethodParameter(p, name, null, false, false));

0 commit comments

Comments
 (0)