此位置不允许使用注释@ApiResponses

问题描述 投票:0回答:1

我收到以下错误:此位置不允许注释@ApiResponses我们正在使用swagger2.2.0

@RestController
@RequestMapping(value = "/example")
@ApiResponses(value = {  @ApiResponse(code = 200, message = "Success"),
        @ApiResponse(code = 204, message = "No Content"),
        @ApiResponse(code = 400, message = "Bad Request"),
        @ApiResponse(code = 401, message = "Unauthorized"),
        @ApiResponse(code = 500, message = "Internal Server Error")})
public class SomeController{

}

如果没有升级swagger版本,我们有任何选择吗?请帮忙..

spring spring-boot swagger swagger-ui swagger-2.0
1个回答
1
投票

这是因为@ApiResponses注释只能用于方法!

以下是一个示例代码段:

 @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
 @ApiResponse(code = 404, message = "Pet not found") })
 public Response getPetById(...) {...}
© www.soinside.com 2019 - 2024. All rights reserved.