Swagger中@ApiResponse注释的可重用性

Swagger中@ApiResponse注释的可重用性,swagger,swagger-2.0,openapi,Swagger,Swagger 2.0,Openapi,我在非spring上下文中使用Swagger注释来记录API。 我发现400、401和404的响应文档是可重用的。 因为它需要大约8行来记录每个响应代码,如下所示 @Operation( summary = "getDetails", description = "someDescription", responses = { @ApiResponse(

我在非spring上下文中使用Swagger注释来记录API。 我发现400、401和404的响应文档是可重用的。 因为它需要大约8行来记录每个响应代码,如下所示

    @Operation(
            summary = "getDetails",
            description = "someDescription",
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Found",
                            content = @Content(mediaType = "application/json",
                                    schema =  @Schema(
                                            name = "Response for success")
                            )
                    ),
                    @ApiResponse(
                            responseCode = "400",
                            description = "Validation failure on inputs.",
                            content = @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(
                                            name = "Response For Bad Request")
                            )
                    ),
                    @ApiResponse(
                            responseCode = "404",
                            description = "Not found",
                            content = @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(
                                            name = "Response For Not Found Request")
                            )

                    ),
                    @ApiResponse(
                            responseCode = "401",
                            description = "Unauthorized",
                            content = @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(
                                            name = "Response For Unauthorized")
                            )
                    )
            }
    )
我打算防止为每个可重用API响应增加行数。 我想要下面这样的

  @Operation(
            summary = "getDetails",
            description = "someDescription",
            responses = {
                   @ApiResponse(
                            responseCode = "200",
                            description = "Found",
                            content = @Content(mediaType = "application/json",
                                    schema =  @Schema(
                                            name = "Response for success")
                            )
                    ),
                    SomeStaticClass.getBadResponseDesc(),
                    SomeStaticClass.getUnauthorizedResponseDesc()
}

在java 8中有什么方法可以实现这一点吗?

是的,在
Docket
对象上使用
globalResponseMessage
。请参阅springfox文档中的,以了解其使用示例。我使用这种方法从代码中删除了大量的
@ApiResponse
注释