@@ -618,16 +618,20 @@ public void applyBeanValidatorAnnotations(final Parameter parameter, final List<
618
618
*/
619
619
public void applyBeanValidatorAnnotations (final RequestBody requestBody , final List <Annotation > annotations , boolean isOptional ) {
620
620
Map <String , Annotation > annos = new HashMap <>();
621
- boolean requestBodyRequired = false ;
621
+ boolean springRequestBodyRequired = false ;
622
+ boolean swaggerRequestBodyRequired = false ;
622
623
if (!CollectionUtils .isEmpty (annotations )) {
623
624
annotations .forEach (annotation -> annos .put (annotation .annotationType ().getSimpleName (), annotation ));
624
- requestBodyRequired = annotations .stream ()
625
+ springRequestBodyRequired = annotations .stream ()
625
626
.filter (annotation -> org .springframework .web .bind .annotation .RequestBody .class .equals (annotation .annotationType ()))
626
627
.anyMatch (annotation -> ((org .springframework .web .bind .annotation .RequestBody ) annotation ).required ());
628
+ swaggerRequestBodyRequired = annotations .stream ()
629
+ .filter (annotation -> io .swagger .v3 .oas .annotations .parameters .RequestBody .class .equals (annotation .annotationType ()))
630
+ .anyMatch (annotation -> ((io .swagger .v3 .oas .annotations .parameters .RequestBody ) annotation ).required ());
627
631
}
628
632
boolean validationExists = Arrays .stream (ANNOTATIONS_FOR_REQUIRED ).anyMatch (annos ::containsKey );
629
633
630
- if (validationExists || (!isOptional && requestBodyRequired ))
634
+ if (validationExists || (!isOptional && ( springRequestBodyRequired || swaggerRequestBodyRequired ) ))
631
635
requestBody .setRequired (true );
632
636
Content content = requestBody .getContent ();
633
637
for (MediaType mediaType : content .values ()) {
@@ -781,8 +785,8 @@ private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo pa
781
785
private boolean checkRequestBodyAnnotation (MethodParameter methodParameter ) {
782
786
return methodParameter .getParameterAnnotation (org .springframework .web .bind .annotation .RequestBody .class ) != null
783
787
|| methodParameter .getParameterAnnotation (io .swagger .v3 .oas .annotations .parameters .RequestBody .class ) != null
784
- || AnnotatedElementUtils .findMergedAnnotation (Objects .requireNonNull (methodParameter .getParameter ()), io .swagger .v3 .oas .annotations .parameters .RequestBody .class ) != null
785
- || AnnotatedElementUtils .findMergedAnnotation (Objects .requireNonNull (methodParameter .getMethod ()), io .swagger .v3 .oas .annotations .parameters .RequestBody .class ) != null ;
788
+ || AnnotatedElementUtils .isAnnotated (Objects .requireNonNull (methodParameter .getParameter ()), io .swagger .v3 .oas .annotations .parameters .RequestBody .class )
789
+ || AnnotatedElementUtils .isAnnotated (Objects .requireNonNull (methodParameter .getMethod ()), io .swagger .v3 .oas .annotations .parameters .RequestBody .class );
786
790
}
787
791
788
792
/**
0 commit comments