I am using Swagger annotations to document API in non-spring context. I find that response documentation for 400, 401 and 404 is reusable. Since it takes around 8 lines to document each response code as shown below.
@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")
)
)
}
)
I intend to prevent bloating the lines for each reusable API response. I would prefer something like below
@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()
}
Is there any way to achieve this in java 8?