11赞
169
当前位置:  开发笔记 > 编程语言 > 正文

为bearerauth添加一个swagger注释

如何解决《为bearerauth添加一个swagger注释》经验,请问有什么解决方案?

我正在开发一个dropwizard REST服务.我使用https://bitbucket.org/b_c/jose4j/wiki/Home在jwt中添加了身份验证

令牌必须进入Authorization标头

Authorization: Bearer [TOKEN]

我想找到一个很好的方法来添加一些swagger注释,以便在swagger-ui上拥有授权标头.

我找到了一个解决方法,隐藏了身份验证参数并添加了一个虚拟参数 @HeaderParam

@POST
@Path("/test/")
public Foo postBar(
        @Auth @ApiParam(hidden = true) Principal user,
        @ApiParam("data") Foo bar,
        @HeaderParam(value="Authorization")String dummy)

这将添加到参数中:

{
  "name" : "Authorization",
  "in" : "header",
  "required" : false,
  "type" : "string"
} 

如果我把@HeadParamPrincipal user我得到的运行时间:

Caused by: org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.

[[FATAL] No injection source found for a parameter of type public java.util.Map com.foo.bar.AppResource.get(java.security.Principal) at index 0.; source='ResourceMethod{httpMethod=GET, cOnsumedTypes=[], producedTypes=[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class com.mykronoz.data.tracking.resources.AppResource, handlerCOnstructors=[org.glassfish.jersey.server.model.HandlerConstructor@6374d682]}, definitiOnMethod=public java.util.Map com.foo.bar.AppResource.get(java.security.Principal), parameters=[Parameter [type=interface java.security.Principal, source=Authorization, defaultValue=null]], respOnseType=java.util.Map}, nameBindings=[]}']

有没有更好的方法呢?


推荐阅读
author-avatar
铁血aaaaaaaaaaaaa_295
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有