Skip to content

Support RequestBody as a meta-annotation #2759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
edudar opened this issue Oct 11, 2024 · 0 comments · Fixed by #2760
Closed

Support RequestBody as a meta-annotation #2759

edudar opened this issue Oct 11, 2024 · 0 comments · Fixed by #2760

Comments

@edudar
Copy link
Contributor

edudar commented Oct 11, 2024

Problem:

io.swagger.v3.oas.annotations.parameters.RequestBody has three targets it can be used on:

  • METHOD
  • PARAMETER
  • ANNOTATION_TYPE

When springdoc resolves annotation in AbstractRequestService.isRequestBodyParam(), it checks if there's such annotation on a parameter directly:

methodParameter.getParameterAnnotation(RequestBody.class) != null

or on a method:

AnnotatedElementUtils.findMergedAnnotation(methodParameter.getMethod(), RequestBody.class) != null

but it does not cover ANNOTATION_TYPE, so any annotation that would use RequestBody as a meta-annotation won't work. This is my case, as I have a special annotation for the request body that is not native to Spring.

Workaround:

Use two annotations:

@MyRequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody

I use full path because the name is the same between one in Swagger and one in Spring, and there are mix-ups.

Solution:

Check if RequestBody is a meta-annotation:

AnnotatedElementUtils.findMergedAnnotation(methodParameter.getParameter(), RequestBody.class) != null

This should cover both PARAMETER and ANNOTATION_TYPE cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant