[BUG][Java][Spring] Multiple "tags" parameters in @Operation annotation
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The OpenAPI generator generates invalid Java SpringBoot code if multiple tags are used in the OpenAPI definition.
The generated @Operation annotation contains all the tags multiple times, depending on how many tags are present.
Here is an example:
@Operation(
operationId = "dummyoperation",
tags = { "tag1", "tag2" },
tags = { "tag1", "tag2" }, // <- this is the invalid duplicate
responses = {
@ApiResponse(responseCode = "200", description = "successful operation")
}
)
This is generated with the latest stable version 5.4.0. We are using spring-boot generator. This is an example project, which demonstrates the error: maven-openapi-generator-poc.zip
OpenAPI declaration file
openapi: 3.0.1
info:
description: Proof of error
title: Proof of error
version: 0.0.1
servers:
- url: http://localhost:8090/api/v1
- url: https://localhost:8090/api/v1
paths:
/dummy:
post:
operationId: dummyoperation
responses:
"200":
content: {}
description: successful operation
tags:
- tag1
- tag2
Maven project description
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>maven-openapi-generator-poc</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.12</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.4.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<configOptions>
<interfaceOnly>false</interfaceOnly>
<basePackage>org.example.base</basePackage>
<configPackage>org.example.config</configPackage>
</configOptions>
<library>spring-boot</library>
<output>${project.build.directory}/generated-sources</output>
<apiPackage>org.example.api</apiPackage>
<modelPackage>org.example.model</modelPackage>
<invokerPackage>org.example.invoke</invokerPackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Generation Details
- Maven SpringBoot project
Steps to reproduce
mvn clean compilein the attached example project maven-openapi-generator-poc.zip. The error is located in the generatedDummyApi.java.
@apr4 can you please try the latest master? We just merged a PR related to multiple "tags" for the spring generator.
@wing328 Yes, it works with the current master (15501f10c44e736872bdce13703f4f25c63793c6).
same issue
Hello all just trying it with gradle plugin generation with spring generator and the issue is still present.(yet it may be a different one)
I am using gradle plugin "org.openapi.generator" version "6.0.0"
A default tag is generated on the <Resource>Api class using the resource name which results in showing all the resources doubled in different tag groups (in the swagger ui)- the first one defined by me in the specification - the second one auto generated by the codegen.
Could you please provide a workaround and suggest a possible fix.
any workaround for this?
A workaround is to download the template in the PR at https://github.com/OpenAPITools/openapi-generator/pull/13434 and place a copy locally in a folder called JavaSpring, and specify it when generating code as described at https://openapi-generator.tech/docs/templating/
e.g. -t (wherever)\templates\JavaSpring
Hopefully the PR will be accepted and in a release soon 🤞