I’m trying to abstract my code so that I would not have to repeat responses for multiple Router Operations. Does there exist a plugin such that responses attribute in the @Operation annotation can be externalized?
@RouterOperation(path = "",
method = POST,
produces = APPLICATION_JSON_VALUE,
beanClass = MyBeanClass.class,
beanMethod = "myBeanMethod",
operation = @Operation(
operationId = "myBeanOperationId",
responses = {
@ApiResponse(responseCode = SwaggerData.POST_SUCCESS_RES_STATUS_202, description = SwaggerData.POST_RES_DESC_202,
content = @Content(schema = @Schema(implementation = AResponse.class))),
@ApiResponse(responseCode = SwaggerData.POST_RES_STATUS_400, description = SwaggerData.POST_JOB_DESC_400,
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = SwaggerData.POST_RES_STATUS_403, description = SwaggerData.POST_JOB_DESC_403,
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = SwaggerData.POST_RES_STATUS_404, description = SwaggerData.POST_JOB_DESC_404,
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = SwaggerData.POST_RES_STATUS_422, description = SwaggerData.POST_JOB_DESC_422,
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = SwaggerData.POST_RES_STATUS_500, description = SwaggerData.POST_JOB_DESC_500,
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
}
)
)
I’ve tried creating reusable annotations but the responses attribute in @Operation is an array of @ApiResponse annotations and I don’t think that Java supports this kind of dynamic unwrapping of annotations.
Victoria Zhang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.