Skip to content

Commit 86b385c

Browse files
committed
code review
1 parent d938062 commit 86b385c

12 files changed

Lines changed: 90 additions & 46 deletions

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/converters/ConverterUtils.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ public static void addResponseTypeToIgnore(Class<?> cls) {
101101
* @return the boolean
102102
*/
103103
public static boolean isResponseTypeWrapper(Class<?> rawClass) {
104-
return RESULT_WRAPPERS_TO_IGNORE.stream().anyMatch(clazz -> clazz.isAssignableFrom(rawClass));
104+
for (Class<?> clazz : RESULT_WRAPPERS_TO_IGNORE) {
105+
if (clazz.isAssignableFrom(rawClass))
106+
return true;
107+
}
108+
return false;
105109
}
106110

107111
/**
@@ -111,7 +115,11 @@ public static boolean isResponseTypeWrapper(Class<?> rawClass) {
111115
* @return the boolean
112116
*/
113117
public static boolean isResponseTypeToIgnore(Class<?> rawClass) {
114-
return RESPONSE_TYPES_TO_IGNORE.stream().anyMatch(clazz -> clazz.isAssignableFrom(rawClass));
118+
for (Class<?> clazz : RESPONSE_TYPES_TO_IGNORE) {
119+
if (clazz.isAssignableFrom(rawClass))
120+
return true;
121+
}
122+
return false;
115123
}
116124

117125
/**
@@ -143,7 +151,11 @@ public static void removeResponseTypeToIgnore(Class<?> classes) {
143151
* @return the boolean
144152
*/
145153
public static boolean isFluxTypeWrapper(Class<?> rawClass) {
146-
return FLUX_WRAPPERS_TO_IGNORE.stream().anyMatch(clazz -> clazz.isAssignableFrom(rawClass));
154+
for (Class<?> clazz : FLUX_WRAPPERS_TO_IGNORE) {
155+
if (clazz.isAssignableFrom(rawClass))
156+
return true;
157+
}
158+
return false;
147159
}
148160

149161
/**
@@ -193,7 +205,11 @@ public static void removeJavaTypeToIgnore(Class<?> classes) {
193205
* @return the boolean
194206
*/
195207
public static boolean isJavaTypeToIgnore(Class<?> rawClass) {
196-
return JAVA_TYPE_TO_IGNORE.stream().anyMatch(clazz -> clazz.isAssignableFrom(rawClass));
208+
for (Class<?> clazz : JAVA_TYPE_TO_IGNORE) {
209+
if (clazz.isAssignableFrom(rawClass))
210+
return true;
211+
}
212+
return false;
197213
}
198214

199215
}

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/converters/SchemaPropertyDeprecatingConverter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ public static void addDeprecatedType(Class<? extends Annotation> cls) {
8484
*/
8585
public static boolean isDeprecated(Method method) {
8686
Class<?> declaringClass = method.getDeclaringClass();
87-
boolean deprecatedMethod = DEPRECATED_ANNOTATIONS.stream().anyMatch(annoClass -> AnnotatedElementUtils.findMergedAnnotation(method, annoClass) != null);
88-
boolean deprecatedClass = DEPRECATED_ANNOTATIONS.stream().anyMatch(annoClass -> AnnotatedElementUtils.findMergedAnnotation(declaringClass, annoClass) != null);
89-
return deprecatedClass || deprecatedMethod;
87+
for (Class<? extends Annotation> annoClass : DEPRECATED_ANNOTATIONS) {
88+
if (AnnotatedElementUtils.findMergedAnnotation(method, annoClass) != null
89+
|| AnnotatedElementUtils.findMergedAnnotation(declaringClass, annoClass) != null)
90+
return true;
91+
}
92+
return false;
9093
}
9194

9295
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static MethodParameter[] customize(String[] pNames, MethodParameter[] par
144144

145145
boolean hasFlatAnnotation = p.hasParameterAnnotation(ParameterObject.class) || AnnotatedElementUtils.isAnnotated(paramClass, ParameterObject.class);
146146
boolean hasNotFlatAnnotation = Arrays.stream(p.getParameterAnnotations())
147-
.anyMatch(annotation -> Arrays.asList(RequestBody.class, RequestPart.class).contains(annotation.annotationType()));
147+
.anyMatch(annotation -> RequestBody.class == annotation.annotationType() || RequestPart.class == annotation.annotationType());
148148
if (!MethodParameterPojoExtractor.isSimpleType(paramClass)
149149
&& (hasFlatAnnotation || (defaultFlatParamObject && !hasNotFlatAnnotation && !AbstractRequestService.isRequestTypeToIgnore(paramClass)))) {
150150
List<MethodParameter> flatParams = new CopyOnWriteArrayList<>();

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ public static void removeRequestWrapperToIgnore(Class<?>... classes) {
244244
* @return the boolean
245245
*/
246246
public static boolean isRequestTypeToIgnore(Class<?> rawClass) {
247-
return PARAM_TYPES_TO_IGNORE.stream().anyMatch(clazz -> clazz.isAssignableFrom(rawClass));
247+
for (Class<?> clazz : PARAM_TYPES_TO_IGNORE) {
248+
if (clazz.isAssignableFrom(rawClass))
249+
return true;
250+
}
251+
return false;
248252
}
249253

250254
/**
@@ -262,8 +266,9 @@ public static Collection<Parameter> getHeaders(MethodAttributes methodAttributes
262266
schema.addEnumItem(entry.getValue());
263267
Parameter parameter = new Parameter().in(ParameterIn.HEADER.toString()).name(entry.getKey()).schema(schema);
264268
ParameterId parameterId = new ParameterId(parameter);
265-
if (map.containsKey(parameterId)) {
266-
parameter = map.get(parameterId);
269+
Parameter existing = map.get(parameterId);
270+
if (existing != null) {
271+
parameter = existing;
267272
List existingEnum = null;
268273
if (parameter.getSchema() != null && !CollectionUtils.isEmpty(parameter.getSchema().getEnum()))
269274
existingEnum = parameter.getSchema().getEnum();

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericParameterService.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ public static void addFileType(Class<?>... classes) {
184184
* @return the boolean
185185
*/
186186
public static boolean isFile(Class type) {
187-
return FILE_TYPES.stream().anyMatch(clazz -> clazz.isAssignableFrom(type));
187+
for (Class<?> clazz : FILE_TYPES) {
188+
if (clazz.isAssignableFrom(type))
189+
return true;
190+
}
191+
return false;
188192
}
189193

190194
/**
@@ -783,8 +787,9 @@ String getParamJavadoc(JavadocProvider javadocProvider, MethodParameter methodPa
783787
Class cls = ((DelegatingMethodParameter) methodParameter).getExecutable().getDeclaringClass();
784788
if (cls.getSuperclass() != null && cls.isRecord()) {
785789
Map<String, String> recordParamMap = javadocProvider.getRecordClassParamJavadoc(cls);
786-
if (recordParamMap.containsKey(fieldName)) {
787-
paramJavadocDescription = recordParamMap.get(fieldName);
790+
String recordDesc = recordParamMap.get(fieldName);
791+
if (recordDesc != null) {
792+
paramJavadocDescription = recordDesc;
788793
}
789794
}
790795

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericResponseService.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ public static void buildContentFromDoc(Components components, ApiResponses apiRe
192192
if (optionalContent.isPresent()) {
193193
Content newContent = optionalContent.get();
194194
if (methodAttributes.isMethodOverloaded() && existingContent != null) {
195-
Arrays.stream(methodAttributes.getMethodProduces()).forEach(mediaTypeStr -> {
195+
for (String mediaTypeStr : methodAttributes.getMethodProduces()) {
196196
io.swagger.v3.oas.models.media.MediaType mediaType = newContent.get(mediaTypeStr);
197197
if (mediaType != null && mediaType.getSchema() != null)
198198
mergeSchema(existingContent, mediaType.getSchema(), mediaTypeStr);
199-
});
199+
}
200200
apiResponse.content(existingContent);
201201
}
202202
else
@@ -433,8 +433,7 @@ private void buildGenericApiResponses(Components components, MethodParameter met
433433
// available
434434
String httpCode = evaluateResponseStatus(methodParameter.getMethod(), Objects.requireNonNull(methodParameter.getMethod()).getClass(), true);
435435
if (Objects.nonNull(httpCode)) {
436-
apiResponse = methodAttributes.getGenericMapResponse().containsKey(httpCode) ? methodAttributes.getGenericMapResponse().get(httpCode)
437-
: new ApiResponse();
436+
apiResponse = methodAttributes.getGenericMapResponse().getOrDefault(httpCode, new ApiResponse());
438437
buildApiResponses(components, methodParameter, apiResponsesOp, methodAttributes, httpCode, apiResponse, true);
439438
}
440439
}
@@ -583,7 +582,8 @@ private Schema<?> calculateSchema(Components components, Type returnType, JsonVi
583582
*/
584583
private void setContent(String[] methodProduces, Content content,
585584
io.swagger.v3.oas.models.media.MediaType mediaType) {
586-
Arrays.stream(methodProduces).forEach(mediaTypeStr -> content.addMediaType(mediaTypeStr, mediaType));
585+
for (String mediaTypeStr : methodProduces)
586+
content.addMediaType(mediaTypeStr, mediaType);
587587
}
588588

589589
/**
@@ -623,7 +623,8 @@ else if (CollectionUtils.isEmpty(apiResponse.getContent()))
623623
Schema<?> schemaN = calculateSchema(components, type,
624624
methodAttributes.getJsonViewAnnotation(), getParameterAnnotations(methodParameter));
625625
if (schemaN != null && ArrayUtils.isNotEmpty(methodAttributes.getMethodProduces()))
626-
Arrays.stream(methodAttributes.getMethodProduces()).forEach(mediaTypeStr -> mergeSchema(existingContent, schemaN, mediaTypeStr));
626+
for (String mediaTypeStr : methodAttributes.getMethodProduces())
627+
mergeSchema(existingContent, schemaN, mediaTypeStr);
627628
}
628629
if (springDocConfigProperties.isOverrideWithGenericResponse()
629630
&& methodParameter.getExecutable().isAnnotationPresent(ExceptionHandler.class)) {
@@ -729,9 +730,10 @@ private Map<String, ApiResponse> getGenericMapResponse(HandlerMethod handlerMeth
729730
})
730731
.toList();
731732

732-
Map<String, ApiResponse> genericApiResponseMap = controllerAdviceInfosInThisBean.stream()
733-
.map(ControllerAdviceInfo::getApiResponseMap)
734-
.collect(LinkedHashMap::new, Map::putAll, Map::putAll);
733+
Map<String, ApiResponse> genericApiResponseMap = new LinkedHashMap<>();
734+
for (ControllerAdviceInfo info : controllerAdviceInfosInThisBean) {
735+
genericApiResponseMap.putAll(info.getApiResponseMap());
736+
}
735737

736738
List<ControllerAdviceInfo> controllerAdviceInfosNotInThisBean = controllerAdviceInfos.stream()
737739
.filter(controllerAdviceInfo ->
@@ -750,20 +752,16 @@ private Map<String, ApiResponse> getGenericMapResponse(HandlerMethod handlerMeth
750752

751753
for (Class<?> exception : exceptions) {
752754
if (isGlobalException(exception) ||
753-
Arrays.stream(methodExceptions).anyMatch(methodException ->
754-
methodException.isAssignableFrom(exception) ||
755-
exception.isAssignableFrom(methodException))) {
755+
matchesAnyMethodException(methodExceptions, exception)) {
756756

757757
addToGenericMap = true;
758758
break;
759759
}
760760
}
761761

762762
if (addToGenericMap || exceptions.isEmpty()) {
763-
methodAdviceInfo.getApiResponses().forEach((key, apiResponse) -> {
764-
if (!genericApiResponseMap.containsKey(key))
765-
genericApiResponseMap.put(key, apiResponse);
766-
});
763+
methodAdviceInfo.getApiResponses().forEach((key, apiResponse) ->
764+
genericApiResponseMap.putIfAbsent(key, apiResponse));
767765
}
768766
}
769767
}
@@ -839,6 +837,21 @@ private Set<Class<?>> getExceptionsFromExceptionHandler(MethodParameter methodPa
839837
}
840838

841839

840+
/**
841+
* Matches any method exception boolean.
842+
*
843+
* @param methodExceptions the method exceptions
844+
* @param exception the exception
845+
* @return the boolean
846+
*/
847+
private boolean matchesAnyMethodException(Class<?>[] methodExceptions, Class<?> exception) {
848+
for (Class<?> methodException : methodExceptions) {
849+
if (methodException.isAssignableFrom(exception) || exception.isAssignableFrom(methodException))
850+
return true;
851+
}
852+
return false;
853+
}
854+
842855
/**
843856
* Is unchecked exception boolean.
844857
*

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/OpenAPIService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private void initializeHiddenRestController() {
283283
Hidden.class) != null)).map(controller -> controller.getValue().getClass())
284284
.collect(Collectors.toList());
285285
if (!CollectionUtils.isEmpty(hiddenRestControllers))
286-
getConfig().addHiddenRestControllers(hiddenRestControllers.toArray(new Class<?>[hiddenRestControllers.size()]));
286+
getConfig().addHiddenRestControllers(hiddenRestControllers.toArray(new Class<?>[0]));
287287
}
288288

289289
/**

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/RequestBodyService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ private void buildRequestBodyContent(io.swagger.v3.oas.annotations.parameters.Re
168168
if (optionalContent.isPresent() && existingContent != null) {
169169
Content newContent = optionalContent.get();
170170
if (methodAttributes.isMethodOverloaded()) {
171-
Arrays.stream(methodAttributes.getMethodProduces()).forEach(mediaTypeStr -> {
171+
for (String mediaTypeStr : methodAttributes.getMethodProduces()) {
172172
io.swagger.v3.oas.models.media.MediaType mediaType = newContent.get(mediaTypeStr);
173173
if (mediaType != null && mediaType.getSchema() != null)
174174
mergeSchema(existingContent, mediaType.getSchema(), mediaTypeStr);
175-
});
175+
}
176176
requestBodyObject.content(existingContent);
177177
}
178178
else

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/SecurityService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public io.swagger.v3.oas.annotations.security.SecurityRequirement[] getSecurityR
144144
public Set<io.swagger.v3.oas.annotations.security.SecurityRequirement> getSecurityRequirementsForMethod(Method method, Set<io.swagger.v3.oas.annotations.security.SecurityRequirement> allSecurityTags) {
145145
io.swagger.v3.oas.annotations.security.SecurityRequirements methodSecurity = AnnotatedElementUtils.findMergedAnnotation(method, io.swagger.v3.oas.annotations.security.SecurityRequirements.class);
146146
if (methodSecurity != null)
147-
allSecurityTags = addSecurityRequirements(allSecurityTags, new HashSet<>(Arrays.asList(methodSecurity.value())));
147+
allSecurityTags = addSecurityRequirements(allSecurityTags, new HashSet<>(List.of(methodSecurity.value())));
148148
if (CollectionUtils.isEmpty(allSecurityTags)) {
149149
// handlerMethod SecurityRequirement
150150
Set<io.swagger.v3.oas.annotations.security.SecurityRequirement> securityRequirementsMethodList = AnnotatedElementUtils.findMergedRepeatableAnnotations(method,
@@ -165,7 +165,7 @@ public Set<io.swagger.v3.oas.annotations.security.SecurityRequirement> getSecuri
165165
Set<io.swagger.v3.oas.annotations.security.SecurityRequirement> allSecurityTags = null;
166166
io.swagger.v3.oas.annotations.security.SecurityRequirements classSecurity = AnnotatedElementUtils.findMergedAnnotation(beanType, io.swagger.v3.oas.annotations.security.SecurityRequirements.class);
167167
if (classSecurity != null)
168-
allSecurityTags = new HashSet<>(Arrays.asList(classSecurity.value()));
168+
allSecurityTags = new HashSet<>(List.of(classSecurity.value()));
169169
if (CollectionUtils.isEmpty(allSecurityTags)) {
170170
// class SecurityRequirement
171171
Set<io.swagger.v3.oas.annotations.security.SecurityRequirement> securityRequirementsClassList = AnnotatedElementUtils.findMergedRepeatableAnnotations(
@@ -363,7 +363,8 @@ private Optional<OAuthFlow> getOAuthFlow(io.swagger.v3.oas.annotations.security.
363363
*/
364364
private Optional<Scopes> getScopes(OAuthScope[] scopes) {
365365
Scopes scopesObject = new Scopes();
366-
Arrays.stream(scopes).forEach(scope -> scopesObject.addString(scope.name(), scope.description()));
366+
for (OAuthScope scope : scopes)
367+
scopesObject.addString(scope.name(), scope.description());
367368
return Optional.of(scopesObject);
368369
}
369370

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/SchemaUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.lang.reflect.Field;
77
import java.lang.reflect.Method;
88
import java.math.BigDecimal;
9-
import java.util.Arrays;
109
import java.util.Collection;
1110
import java.util.HashSet;
1211
import java.util.List;
@@ -57,14 +56,14 @@ public class SchemaUtils {
5756
* The constant ANNOTATIONS_FOR_REQUIRED.
5857
*/
5958
// using string litterals to support both validation-api v1 and v2
60-
public static final List<String> ANNOTATIONS_FOR_REQUIRED = Arrays.asList("NotNull", "NonNull", "NotBlank",
59+
public static final List<String> ANNOTATIONS_FOR_REQUIRED = List.of("NotNull", "NonNull", "NotBlank",
6160
"NotEmpty");
6261

6362
/**
6463
* The constant ANNOTATIONS_FOR_NULLABLE.
6564
*/
6665
public static final List<String> ANNOTATIONS_FOR_NULLABLE =
67-
Arrays.asList("Nullable");
66+
List.of("Nullable");
6867
/**
6968
* The constant OPTIONAL_TYPES.
7069
*/

0 commit comments

Comments
 (0)