Skip to content

Commit 6fda038

Browse files
authored
Added support for RequestBody as a meta-annotation
The change uses advanced `AnnotatedElementUtils` to find annotation instead of simple `getParameterAnnotation`. Resolves #2759
1 parent cc96c71 commit 6fda038

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -766,14 +766,24 @@ private boolean isRequestBodyParam(RequestMethod requestMethod, ParameterInfo pa
766766

767767
return (isBodyAllowed && (parameterInfo.getParameterModel() == null || parameterInfo.getParameterModel().getIn() == null) && !delegatingMethodParameter.isParameterObject())
768768
&&
769-
((methodParameter.getParameterAnnotation(io.swagger.v3.oas.annotations.parameters.RequestBody.class) != null
770-
|| methodParameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestBody.class) != null
771-
|| AnnotatedElementUtils.findMergedAnnotation(Objects.requireNonNull(methodParameter.getMethod()), io.swagger.v3.oas.annotations.parameters.RequestBody.class) != null)
769+
(checkRequestBodyAnnotation(methodParameter)
772770
|| checkOperationRequestBody(methodParameter)
773771
|| checkFile(methodParameter)
774772
|| Arrays.asList(methodAttributes.getMethodConsumes()).contains(MULTIPART_FORM_DATA_VALUE));
775773
}
776774

775+
/**
776+
* Checks whether Swagger's or Spring's RequestBody annotation is present on a parameter or method
777+
*
778+
* @param methodParameter the method parameter
779+
* @return the boolean
780+
*/
781+
private boolean checkRequestBodyAnnotation(MethodParameter methodParamater) {
782+
return methodParameter.getParameterAnnotation(org.springframework.web.bind.annotation.RequestBody.class) != null
783+
|| AnnotatedElementUtils.findMergedAnnotation(Objects.requireNonNull(methodParameter.getParameter()), io.swagger.v3.oas.annotations.parameters.RequestBody.class) != null
784+
|| AnnotatedElementUtils.findMergedAnnotation(Objects.requireNonNull(methodParameter.getMethod()), io.swagger.v3.oas.annotations.parameters.RequestBody.class) != null
785+
}
786+
777787
/**
778788
* Check file boolean.
779789
*

0 commit comments

Comments
 (0)