swagger-core
swagger-core copied to clipboard
Not possible to DRY @Schema annotation
Hi guys,
I'm able to DRY @ApiResponses annotation like so:
@ApiResponses(value = {
@ApiResponse(
responseCode = "4XX", description = "Client Error",
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = com.merchant.model.root.response.Error.class)),
headers = {
@Header(name = ApiConstants.X_REQUEST_ID,
description = ApiConstants.Docs.X_REQUEST_ID_DESCRIPTION,
schema = @Schema(type = ApiConstants.Docs.STRING_TYPE, format = ApiConstants.Docs.UUID_FORMAT))
}),
@ApiResponse(
responseCode = "5XX", description = "Server Error",
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = com.merchant.model.root.response.Error.class)),
headers = {
@Header(name = ApiConstants.X_REQUEST_ID,
description = ApiConstants.Docs.X_REQUEST_ID_DESCRIPTION,
schema = @Schema(type = ApiConstants.Docs.STRING_TYPE, format = ApiConstants.Docs.UUID_FORMAT))
})
})
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiErrorResponses { }
That makes it possible to reduce repetition by just adding @ApiErrorResponses annotation to all my endpoints.
However, this approach doesn't currently work with the @Schema annotation. Does anybody know why? And is there a good way of reusing swagger annotations?
Thanks!
It would be good to use @Schema and @ArraySchema from swagger-annotations in meta-annotation.
The alternative to use a schema reference is more complicated to define and makes problem with array after code generation from the generated open-api.