I'm working on the implementation of various REST services, using Spring MVC. For documentation, I'm using Swagger.
This works nice and the documentation looks good and is really functional. The only problem I have is that the annotations for documentation really crowd the controller classes, especially the error code annotations.
Example:
@ApiErrors(value = {
@ApiError(code = 123, reason = "Reason123"),
@ApiError(code = 124, reason = "Reason124"),
@ApiError(code = 125, reason = "Reason125"),
@ApiError(code = 126, reason = "Reason126"),
@ApiError(code = 127, reason = "Reason127") })
public void exampleFunctionImplementation() {
}
In many cases, this leads to large blocks of annotations where the real application code is hidden somewhere in between. In addition, this annotation sets are often repeated, as a lot of methods may return the same set of error codes.
Is there any option to shorten this a bit through defining the annotation list somewhere else as a constant in another class file? Or maybe something even more simple I may have overlooked?
I tried with defining the array of @ApiError
items somewhere, but this won't compile:
ApiError[] array = {ApiError(code = 123, reason = "Reason123")};
I would be glad if anybody could give me a hint how to solve this problem, thanks in advance!