首页 > 解决方案 > Swagger Annotations 不显示正文示例

问题描述

使用 Swagger Annotations 时,无法为请求正文创建示例。

生成 Swagger 页面但缺少 Json

这是 RESTful 资源/端点的注释内容:

 @POST
@Path("/{carId}/conversation")
@ApiImplicitParams({
        @ApiImplicitParam(name = "Authorization", value = "The AppJWT token", paramType = "header", required = true),
        @ApiImplicitParam(name = "ON-BEHALF", value = "The ConsumerJWS token", paramType = "header", required = true),
        @ApiImplicitParam(name = "v", value = "API version", defaultValue = "3", paramType = "query", required = true)
})
@ManagedAsync
@ApiOperation(value = "bla", notes = "")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "bla", response = CreateBlaResponse.class, responseContainer = "List"),
        @ApiResponse(code = 400, message = "The input was invalid, please check.", response = GenericError.class),
        @ApiResponse(code = 401, message = "Unauthorized. Are the headers correct?"),
        @ApiResponse(code = 429, message = "Too many requests, please try again later", response = CreateConversationResBody.class)
})
public void createConversationBatchPOST(@ApiParam(value = "Car ID the action should apply to", required = true) @PathParam("carId") String carId,
                                        @ApiParam(name = "body", value = "The Json payload", required = true, examples = @Example(value = {@ExampleProperty(value = "{\"name\" : \"James\"}", mediaType = "application/json")}))
                                        @RequestBody String body,
                                        @Suspended final AsyncResponse asyncResponse) throws IOException {
//.... implementation
}

你知道为什么方法签名中的注释

     @ApiParam(name = "body", value = "The Json payload", 
required = true, examples = @Example(value = {@ExampleProperty(value = "{\"name\" : \"James\"}", mediaType = "application/json")})) 
@RequestBody String body

不会导致 Json 示例?

标签: swagger-2.0

解决方案


推荐阅读