Skip to content

Commit 54510ad

Browse files
author
bnasslahsen
committed
code review
1 parent 710ad02 commit 54510ad

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ protected Parameter customiseParameter(Parameter parameter, ParameterInfo parame
255255
protected boolean isParamToIgnore(MethodParameter parameter) {
256256
if (parameterBuilder.isAnnotationToIgnore(parameter))
257257
return true;
258-
if ((parameter.getParameterAnnotation(PathVariable.class) != null && parameter.getParameterAnnotation(PathVariable.class) .required())
258+
if ((parameter.getParameterAnnotation(PathVariable.class) != null && parameter.getParameterAnnotation(PathVariable.class).required())
259259
|| (parameter.getParameterAnnotation(RequestParam.class) != null && parameter.getParameterAnnotation(RequestParam.class).required())
260260
|| (parameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestBody.class) != null && parameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestBody.class).required()))
261261
return false;
@@ -374,14 +374,16 @@ private void applyBeanValidatorAnnotations(final Parameter parameter, final List
374374

375375
private void applyBeanValidatorAnnotations(final RequestBody requestBody, final List<Annotation> annotations, boolean isOptional) {
376376
Map<String, Annotation> annos = new HashMap<>();
377-
if (annotations != null)
377+
boolean requestBodyRequired = false;
378+
if (annotations != null) {
378379
annotations.forEach(annotation -> annos.put(annotation.annotationType().getName(), annotation));
380+
requestBodyRequired = annotations.stream()
381+
.filter(annotation -> org.springframework.web.bind.annotation.RequestBody.class.equals(annotation.annotationType()))
382+
.anyMatch(annotation -> ((org.springframework.web.bind.annotation.RequestBody) annotation).required());
383+
}
379384
boolean validationExists = Arrays.stream(ANNOTATIONS_FOR_REQUIRED).anyMatch(annos::containsKey);
380-
boolean requestBodyRequired = annotations.stream()
381-
.filter(annotation -> org.springframework.web.bind.annotation.RequestBody.class.equals(annotation.annotationType()))
382-
.anyMatch(annotation -> ((org.springframework.web.bind.annotation.RequestBody) annotation).required());
383385

384-
if (validationExists || (!isOptional && requestBodyRequired) )
386+
if (validationExists || (!isOptional && requestBodyRequired))
385387
requestBody.setRequired(true);
386388
Content content = requestBody.getContent();
387389
for (MediaType mediaType : content.values()) {

0 commit comments

Comments
 (0)