3

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?

1 Answer 1

4

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...

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.