Swagger Java common header

こ雲淡風輕ζ 提交于 2019-12-19 00:23:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!