使用swagger在Response中返回示例json

时间:2016-12-22 14:01:52

标签: jersey swagger jersey-2.0 dropwizard

我使用swwger和我的dropwizard应用程序进行API文档和非依赖UI开发。

我必须返回模拟响应,它可以包含我创建的样本序列化响应对象。

例如: -

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get User")
@PermitAll
@Path("/users/{userId}")
@ApiResponses(value = {
        @ApiResponse(code = HttpStatus.OK_200, message = "User", response = User.class),
        @ApiResponse(code = HttpStatus.FORBIDDEN_403, message = "You are not authorised"),
        @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "User Not Found!"),
})
public User getUser(@PathParam("userId") String userId) {
}

我想返回由我创建的示例(模拟)用户对象。我总是可以在我的实际控制器函数中添加该代码,直到我编写实际实现的时间,但这不是一个干净的解决方案,而且我希望我的模拟响应与实际响应并行运行。

我浏览了swagger-core文档,发现有模拟请求(通过@Example注释)而不是模拟响应。

有办法吗?

0 个答案:

没有答案