我正在将dropwizard-swagger集成到一个大型现有项目中 . 我现在已经启动并运行了 Swagger UI
endpoints ,但我注意到每个方法都必须具有body参数似乎是坚定的 .
具体而言,方法定义中没有 @ApiParam
注释的第一个参数将被解释为请求主体 . 似乎没有办法指定一个body参数,也似乎没有办法排除 Swagger UI
自动标记参数 . 这意味着"Try it Out"功能不适用于大部分 endpoints ,因为规范不允许使用实体,但 Swagger UI
始终坚持它们存在 .
例如,请考虑 UserResource
文件中的以下方法:
@GET
@Path("v1/users/{userId}/subscriptions")
@ApiOperation(value = "Get user subscriptions", notes = "Returns information about the users current and past subscriptions.")
@UserAccessRequired
@RolesAllowed({//a list of appropriate roles})
@Produces(CompanyMediaType.APPLICATION_API_V1_JSON)
public SubscriptionsDTOV1 getSubscriptionsForUser(@Auth DashboardUser dashboardUser, @JooqInject DSLContext database,
@Context ResourceContext resourceContext,
@Context ContainerRequestContext crc,
@ApiParam(value = "ID of user", type = "Integer") @NotNull @UnwrapValidatedValue @PathParam("userId") IntParam userId) {
Swagger将第一个参数_2534296解释为请求主体,并在 Swagger UI
中生成以下视图:
Swagger UI with a body parameter
因为这是一个 GET
,所以不允许有一个正文,并且在测试时尝试删除 Swagger UI
中正文的内容不起作用,因为该字段使用 {}
自动填充 .
我如何向 Swagger
表明这里没有身体参数并让它工作?只需将 @ApiParam
放在其他方法参数的前面,也不会出现 @QueryParam
/ @PathParam
/ etc注释 .
1 回答
原来添加@ApiParam(hidden = true)似乎已经完成了这个伎俩 . 我之前尝试过这个并没有得到结果,一定是在某处发生了错字 .