问题
I have a REST API server implemented with Jersey2.0
and integrated with Swagger
to automate docs and client side applications.
We have our own authentication header (X-Auth-Token
) which should be applied to all requests in order to use them (Beside the login request that retrieves the token if credentials are correct).
Right now I need to manually add the the token as ApiImplicitParam
annotation to each of the requests in order for the generated docs to include it:
@ApiImplicitParams({@ApiImplicitParam(name = AuthFilter.AUTHORIZATION_PROPERTY, value = "Authorization token", required = true, dataType = "string", paramType = "header")})
I don't want to hardcode the UI code to add the header itself, as I believe it violated the API encapsulation provided by swagger.json
. The server definition should provide all the details necessary for the generated docs.
Is there a way to define a custom default annotation for all requests in Swagger
? Or alternatively use some kind of Filter
to achieve it?
来源:https://stackoverflow.com/questions/35267845/swagger-java-common-header