是否可以创建“常规” Swagger注释?

时间:2019-04-03 21:24:04

标签: java rest annotations swagger endpoint

首先,我进行了很多搜索,但是已经创建的任何问题都可以解决我的问题。在我的项目中,我们有很多使用 swagger 的端点,而我的问题是我们必须为它们编写很多类似的代码才能完成文档,它们之间的区别是响应对象的类型以及“值”和“注释”参数。我想知道是否有可能创建一个自己的自定义批注,该批注集成了获取文档所需的所有代码,当然还有一种在每个参数中设置这3个不同参数的方式,这会使我们的代码更加整洁。 这是我们所有端点中的代码的示例

@ApiOperation(
        value = "Endpoint 1 example",
        notes = "Endpoint 1 example notes",
        responseHeaders = {
                @ResponseHeader(name = RESPONSE_HEADER_X_CONVERSATION_ID,
                        description = RESPONSE_HEADER_DESCRIPTION_X_CONVERSATION_ID,
                        response = String.class),
                @ResponseHeader(name = RESPONSE_HEADER_X_CORRELATION_ID,
                        description = RESPONSE_HEADER_DESCRIPTION_X_CORRELATION_ID,
                        response = String.class),
                @ResponseHeader(name = "X_Implementation_Version",
                        description = "Implementation version of the service",
                        response = String.class)
        }
)
@ApiImplicitParams(
        {
                @ApiImplicitParam(name = RESPONSE_HEADER_AUTHORIZATION,
                        value = RESPONSE_HEADER_DESCRIPTION_AUTHORIZATION,
                        required = true,
                        paramType = PARAM_TYPE_HEADER
                ),
                @ApiImplicitParam(name = "Accept",
                        value = "Describes content type and API version. If API version is not specified, the lowest supported version is assumed.",
                        required = true,
                        paramType = PARAM_TYPE_HEADER
                ),
                @ApiImplicitParam(name = RESPONSE_HEADER_X_CONVERSATION_ID,
                        value = RESPONSE_HEADER_DESCRIPTION_X_CONVERSATION_ID,
                        paramType = PARAM_TYPE_HEADER
                ),
                @ApiImplicitParam(name = RESPONSE_X_APP_ID,
                        value = RESPONSE_HEADER_DESCRIPTION_X_APP_ID,
                        paramType = PARAM_TYPE_HEADER
                )
        }
)
@ApiResponses(
        {
                @ApiResponse(code = 200, message = RESPONSE_CODE_200_MESSAGE,
                        response = ResponseForEndpoint1.class),
                @ApiResponse(code = 400, message = RESPONSE_CODE_400_MESSAGE,
                        response = Error.class),
                @ApiResponse(code = 401, message = RESPONSE_CODE_401_MESSAGE,
                        response = Error.class),
                @ApiResponse(code = 404, message = RESPONSE_CODE_404_RESOURCE_NOT_FOUND_MESSAGE,
                        response = Error.class),
                @ApiResponse(code = 406, message = RESPONSE_CODE_406_FORMAT_NOT_SUPPORTED,
                        response = Error.class),
                @ApiResponse(code = 500, message = RESPONSE_CODE_500_MESSAGE,
                        response = Error.class),
                @ApiResponse(code = 503, message = RESPONSE_CODE_503_MESSAGE,
                        response = Error.class)
        }
)
public ResponseForEndpoint1 exampleMethod() {...};

注意:为清楚起见,我想知道是否有一种方法可以创建一个新的注释,该注释集成了上面显示的Swagger注释,从而最大程度地减少了我们为每个端点编写的代码

0 个答案:

没有答案