Forum Discussion

faisal6621's avatar
faisal6621
Occasional Contributor
3 years ago

Error Sibling parameters must have unique name

There is an archived thread with same title but even today I had the same issue.

If the @Parameter annotation is used at method level and the @QueryParam is present at method parameter level then there are two entries generated by the swagger-maven-plugin.

Source code:

@GET
@Produces(MediaType.APPLICATION_JSON)
@Operation(parameters = {
@Parameter(in = ParameterIn.QUERY, name = "id", description = "id of the file to download", required = true),
@Parameter(in = ParameterIn.QUERY, name = "file", description = "The name of the file to download", required = true),
@Parameter(in = ParameterIn.QUERY, name = "date", description = "File date", required = true)
}
)
public Response download(
@QueryParam("id") String id,
@QueryParam("file") String file,
@QueryParam("date") String date
)
{
return Response.ok().build();
}

 The API generated:

paths:
/download:
get:
operationId: download
parameters:
- name: id
in: query
description: id of the file to download
required: true
schema:
type: string
- name: file
in: query
description: The name of the file to download
required: true
schema:
type: string
- name: date
in: query
description: File date
required: true
schema:
type: string
- name: id
in: query
schema:
type: string
- name: file
in: query
schema:
type: string
- name: date
in: query
schema:
type: string
responses:
default:
description: default response
content:
application/json: {}

 

The rendered response in Swagger editor looks like:

with errors:

 

The maven dependency and plugin I had defined in my pom.xml are as:

<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.1.12</version>
</dependency>
<plugin>
<groupId>io.openapitools.swagger</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>2.1.6</version>
<configuration>
<swaggerConfig>
<info>
<title>REST Endpoints</title>
<description>Available REST Endpoints exposed by my-project.</description>
<contact>
<name>My project team</name>
<url>https://my-project.somecompany.com/</url>
</contact>
<version>1.0</version>
</info>
</swaggerConfig>
<resourcePackages>
<resourcePackage>my.project.package</resourcePackage>
</resourcePackages>
<outputDirectory>${basedir}/api/</outputDirectory>
<outputFilename>my-project-OpenApi</outputFilename>
<outputFormats>YAML</outputFormats>
<prettyPrint>true</prettyPrint>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>

 

How can I prevent generation of duplicate parameters when using the @Operation or @Parameter annotation at method level?

No RepliesBe the first to reply