I'm using swagger annotations to document an api, and they're quite verbose. I find myself repeating certain annotations verbatim. like:
public Response myAPI(
@Parameter(
description = "Some long long description",
required = true,
schema = @Schema(allowableValues = {"abc", "def", "hij"}, defaultValue = "abc"))
@QueryParam("foo") String foo) {
}
What I'd love to have is:
static Parameter myRepeatingParam = @Parameter(
description = "Some long long description",
required = true,
schema = @Schema(allowableValues = {"abc", "def", "hij"},
defaultValue = "abc"));
public Response myAPI01(
@myRepeatingParam
@QueryParam("foo") String foo) {
}
public Response myAPI02(
@myRepeatingParam
@QueryParam("foo") String foo) {
}
Update
Using the meta-annotations works some places, but not others. For instance, given:
@Target({PARAMETER, METHOD, FIELD, ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Parameter(in = ParameterIn.QUERY, name = "foo")
public @interface TestSwagger {
}
This compiles:
public Response myAPI(
@TestSwagger
@QueryParam("foo") String foo) {
return null;
}
But in this use case it does not, because @TestSwagger
isn't a @Parameter
and there appears to be no polymorphism in this case.
@Operation(
parameters = { // array of @Parameters
@TestSwagger,
@Parameter(in = ParameterIn.QUERY, name = "bar")},
)
public Response myAPINope(
@QueryParam("foo") String foo,
@QueryParam("bar") String bar) {
return null;
}
This 2nd case is more what I'm going after and doesn't seem possible.