I'm just starting out with OpenAPI and learning about the different annotations in version 3.0 using Javadoc, as I haven't found any posts specifically about them.
If I use the parameters parameter in the @Operation annotation, the generated documentation duplicates the parameters, that is, it displays the parameters described in parameters and in the RESTful method signatures.
Personally, I prefer using parameters to better organize the code. So, I ask: is it possible to configure something in somewhere to use the parameters parameter in the @Operation annotation?
Here is my configuration in the pom.xml file:
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-annotations-jakarta -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
<version>${io.swagger.core.v3.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-jaxrs2-jakarta -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2-jakarta</artifactId>
<version>${io.swagger.core.v3.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-jaxrs2-servlet-initializer-jakarta -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2-servlet-initializer-jakarta</artifactId>
<version>${io.swagger.core.v3.version}</version>
</dependency>
Here's a sample of both:
#1 Using parameters in @Operation annotation:
@Operation(
summary="Get some data",
description="Get all data available",
parameters= {
@Parameter(
name="issuer",
description="Doc issuer",
required=true,
example="1",
in=ParameterIn.PATH,
allowEmptyValue=false,
schema=@Schema(
type="integer",
implementation=Integer.class,
pattern="\\d+"
)
)
},
responses={
@ApiResponse(responseCode="200",
description="All available data",
content={
@Content(mediaType=MediaType.APPLICATION_JSON),
@Content(mediaType=MediaType.APPLICATION_XML)
}
)
}
)
@GET @Path("issuer/{issuer:\\d+}")
public Response findByIssuer(@PathParam("issuer") Integer issuer) {
...
}
#2 Using @Parameter in method signature:
@Operation(
summary="Get some data",
description="Get all data available",
responses={
@ApiResponse(responseCode="200",
description="All available data",
content={
@Content(mediaType=MediaType.APPLICATION_JSON),
@Content(mediaType=MediaType.APPLICATION_XML)
}
)
}
)
@GET @Path("issuer/{issuer:\\d+}")
public Response findByIssuer(
@Parameter(name="issuer",
description="Get all data available"
)
@PathParam("issuer") Integer issuer) {
...
}
When I use
#1: Services documentation shows issuer duplicated;
#2: Services documentation shows issuer just once.
This is an example with just one parameter (@PathParam), but with methods with a few more parameters (@PathParam / @QueryParam) #2 gets messy and I'd like to use #1 but I don't know if it's possible and, if it is, which configuration I should apply and where.
@PathParam/@QueryParam/@Parameter/ etc. notparameters; see the docs.