swagger-api / swagger-api/swagger-codegen

Incorrect Import Statement for Resource Class in Generated Code with Swagger Codegen v3.0.46

Open
#12,516 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I have a swagger that has "Resource" on of it's swagger models.

When generating code using Swagger Codegen v3.0.46 and above, the generated ApiApi class includes the following incorrect import statement:

import org.springframework.core.io.Resource;

However, the application requires the import to point to a custom class which is part of my swagger:

import com.org.web.dto.Resource;

This issue occurs specifically for the Resource class, which conflicts with org.springframework.core.io.Resource due to naming overlap.

Swagger-codegen version

v3.0.46

Swagger declaration file content or url
Command line used for generation

JDK21
spring boot 3.4.1
io.swagger.codegen.v3
swagger-codegen-maven-plugin
3.0.46

Steps to reproduce

generate the swagger model classes and it won't compile due to importing the wrong Resource class.

Related issues/PRs
Suggest a fix/enhancement

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with a Swagger model named Resource using the swagger-codegen-maven-plugin at v3.0.46, then trace generation of the ApiApi class and its imports. Done means generated code imports the custom com.org.web.dto.Resource class rather than org.springframework.core.io.Resource and compiles successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.