Bug Report Checklist
Description
If the spec defines a model named Tag and an api returns/accepts it, the generated Spring api
imports both the model and io.swagger.v3.oas.annotations.tags.Tag. Two single-type-imports of the same
simple name is a hard javac error, so the generated code does not compile.
error: a type with the same simple name is already defined by the single-type-import of Tag
This is not an ambiguity that a wildcard import could resolve — both imports are explicit.
openapi-generator version
7.25.0-SNAPSHOT, built from master at commit 4aed9c1c635.
OpenAPI declaration file content or url
openapi: 3.0.3
info: { title: t, version: 1.0.0 }
tags: [{ name: pets }]
paths:
/tag:
get:
tags: [pets]
operationId: getTag
responses:
"200":
description: ok
content:
application/json:
schema: { $ref: "#/components/schemas/Tag" }
components:
schemas:
Tag:
properties:
id: { type: string }
Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i spec.yaml -g spring -o out \
--additional-properties=interfaceOnly=true,useSpringBoot3=true
Steps to reproduce
- Save the spec above as
spec.yaml
- Run the command above
- Look at
out/src/main/java/org/openapitools/api/TagApi.java
Actual output
import org.openapitools.model.Tag; // line 8
...
import io.swagger.v3.oas.annotations.tags.Tag; // line 18
...
@Tag(name = "pets", description = "the pets API")
public interface TagApi {
default ResponseEntity<Tag> getTag(...)
Both Tag types are imported explicitly — javac rejects the file.
Expected output
The model import is the one that matters (it is the type used in the signature), so the annotation should
be referenced by its fully qualified name and not imported:
import org.openapitools.model.Tag;
...
@io.swagger.v3.oas.annotations.tags.Tag(name = "pets", description = "the pets API")
public interface TagApi {
default ResponseEntity<Tag> getTag(...)
Suggest a fix
In SpringCodegen.postProcessOperationsWithModels, detect that the file being generated imports the model
Tag, and in that case have JavaSpring/api.mustache and JavaSpring/apiController.mustache emit the
fully qualified annotation and skip import io.swagger.v3.oas.annotations.tags.Tag;.
The check has to be per api file (based on that file's imports), not "does the spec contain a model named
Tag" — the sample petstore spec defines a Tag model, but most of its api files never import it, and
qualifying the annotation there would be needless churn.
I have a patch with a regression test ready and will open a PR shortly.
Related issues/PRs
Searched open and closed issues/PRs for Tag model name clashes in the Spring generator; I could not find
an existing report.
Bug Report Checklist
Description
If the spec defines a model named
Tagand an api returns/accepts it, the generated Spring apiimports both the model and
io.swagger.v3.oas.annotations.tags.Tag. Two single-type-imports of the samesimple name is a hard javac error, so the generated code does not compile.
This is not an ambiguity that a wildcard import could resolve — both imports are explicit.
openapi-generator version
7.25.0-SNAPSHOT, built frommasterat commit4aed9c1c635.OpenAPI declaration file content or url
Generation Details
Steps to reproduce
spec.yamlout/src/main/java/org/openapitools/api/TagApi.javaActual output
Both
Tagtypes are imported explicitly — javac rejects the file.Expected output
The model import is the one that matters (it is the type used in the signature), so the annotation should
be referenced by its fully qualified name and not imported:
Suggest a fix
In
SpringCodegen.postProcessOperationsWithModels, detect that the file being generated imports the modelTag, and in that case haveJavaSpring/api.mustacheandJavaSpring/apiController.mustacheemit thefully qualified annotation and skip
import io.swagger.v3.oas.annotations.tags.Tag;.The check has to be per api file (based on that file's imports), not "does the spec contain a model named
Tag" — the sample petstore spec defines aTagmodel, but most of its api files never import it, andqualifying the annotation there would be needless churn.
I have a patch with a regression test ready and will open a PR shortly.
Related issues/PRs
Searched open and closed issues/PRs for
Tagmodel name clashes in the Spring generator; I could not findan existing report.