I have few controller classes that all requires a header param. To document swagger I am adding this @Parameter annotation to all my endpoints:
@Parameter(in = ParameterIn.HEADER, description = "some description", name = "some name", content = @Content(schema = @Schema(allowableValues = {VALUE1, VALUE2, VALUE3, VALUE4})))
@GetMapping
public void method(@RequestHeader .....) {
//some code here
}
Problem is I don't like the idea of repeating the same annotation all over the controller methods. Is there a nice clean solution to have a reusable annotation here?
So partial fix is create my own custom interface like that:
@Target({PARAMETER, METHOD, FIELD, ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Parameter(in = ParameterIn.HEADER, description = "some description", name = "some name", content = @Content(schema = @Schema(allowableValues = {VALUE1, VALUE2, VALUE3, VALUE4})))
public @interface MyCustomAnnotation {
}
that way I can reuse that and save some code. Problem is when some values differ. For example if allowableValues differ between endpoints I can't reuse that one. I can't figure out how can I pass some arguments to my custom annotation to override the default values...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With