Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reuse complex spring-fox swagger annotation

I am using the spring-fox2 @ApiImplicitParam annotation to make the swagger-ui show a box for including an Authorization header with a request:

@ApiImplicitParams({
        @ApiImplicitParam(
                name="Authorization",
                value="authorization header containing the bearer token",
                paramType = "header"
        )
})
public void someControllerMethod() {
    ...
}

This works fine, but I need this authorization header for each method in the controller. Copying and pasting this is code smell. Can I define some kind of shortcut annotation for this? Is there a different way of telling swagger-ui to create an input field for the authorization header?

Thanks!

like image 881
user152468 Avatar asked Oct 19 '22 12:10

user152468


1 Answers

An alternative approach to you problem is to not use annotations at all. Instead use the docket to add global operation parameters see #22. You can add headers to all the operations in your docket.

The downside to this approach might be that you might end up with multiple dockets configured such that you pre-select (see #4, #5, #6) which operations to add these parameters to.

like image 85
Dilip Krishnan Avatar answered Oct 27 '22 21:10

Dilip Krishnan