2

I have two custom annotations which need to be created to be added on controller endpoints both have the same property @ApiImplicitParams swagger annotation.

For many endpoints i need to use ApiImplicitParams from both annotations but in this case since both have @ApiImplicitParams property hence only one of the @ApiImplicitParams from the two annotations is being used.

I want ApiImplicitParam from both the annotations to be used, how can i acheive this?

CustomAnnotation1

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@ApiImplicitParams({
    @ApiImplicitParam(
   name= "customannotation1",
   value= "value",
   datatype = "string",
   paramtype = "header",
   required= true
)})
public @interface CustomAnnotation1{

}

CustomAnnotation2

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@ApiImplicitParams({
    @ApiImplicitParam(
   name= "customannotation2",
   value= "value",
   datatype = "string",
   paramtype = "header",
   required= true
)})
public @interface CustomAnnotation2{

}
Jayesh Mulwani
  • 655
  • 6
  • 19

1 Answers1

0

Late answer and not applicable for all use-cases, but a possible workaround can be to set @Target({ElementType.TYPE}) on one of the annotations. If you use your CustomAnnotation1 at class level, and CustomAnnotation2 at method level, Swagger will pick up and apply both of them correctly.

Obvious caveats:

  • You need to modify the annotation, which not always be possible or desirable
  • The class level annotation affects all other methods too, which might or might not be what you want
ThomasK
  • 1
  • 1