Skip to content

Support RequestBody as a meta-annotation #2759

Closed
@edudar

Description

@edudar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions