请参见下面的2个示例方法,常见的 ApiResponse 错误500.理想情况下,我只想定义一次.有什么最佳做法和/或建议吗?下面的示例代码:@GET@Path("/greeting")@Produces(MediaType.APPLICATION_JSON)@ApiOperation(value = "Returns greeting details", notes = "Returns .....", response = Greeting.class)@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of greeting details", response = Greeting.class), @ApiResponse(code = 404, message = "Greeting does not exist"), @ApiResponse(code = 500, message = "Internal server error")})public Response getGreeting(.....) { ...}@GET@Path("/something")@Produces(MediaType.APPLICATION_JSON)@ApiOperation(value = "Returns something details", notes = "Returns .....", response = Something.class@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of greeting details", response = Something.class), @ApiResponse(code = 404, message = "Something does not exist"), @ApiResponse(code = 500, message = "Internal server error")})public Response getSomething(.....) { ...}专门指:@ApiResponse(code = 500, message = "Internal server error")先谢谢您.解决方案,您可以创建使用ApiResponses批注的自定义批注.并在方法级别使用此自定义注释.@ApiResponses()公共@interface CustomApiResponse {} Admittedly, I didn't look too hard for an answer. My question is, when defining swagger annotations using springfox-swagger-ui, how does one define common ApiResponse used for more then one method and potentially more then one class?See the 2 sample methods below the common ApiResponse is error 500. Ideally, I would want to define that once. Any best practices and/or suggestions?Sample code below:@GET@Path("/greeting")@Produces(MediaType.APPLICATION_JSON)@ApiOperation(value = "Returns greeting details", notes = "Returns .....", response = Greeting.class)@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of greeting details", response = Greeting.class), @ApiResponse(code = 404, message = "Greeting does not exist"), @ApiResponse(code = 500, message = "Internal server error")})public Response getGreeting(.....) { ...}@GET@Path("/something")@Produces(MediaType.APPLICATION_JSON)@ApiOperation(value = "Returns something details", notes = "Returns .....", response = Something.class@ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of greeting details", response = Something.class), @ApiResponse(code = 404, message = "Something does not exist"), @ApiResponse(code = 500, message = "Internal server error")})public Response getSomething(.....) { ...}Specifically referring to:@ApiResponse(code = 500, message = "Internal server error")Thank you, in advance. 解决方案 you can create custom annotation which use ApiResponses annotation.And use this custom annotation at method level.@ApiResponses()public @interface CustomApiResponse {} 这篇关于定义通用的标注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-09 20:32