swagger-api / swagger-api/swagger-core

Classes / enums with same name but different package replace each other

Open
#4,789 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

If your project has two or more classes (also enums) with the same name (but different packages) they replace each other during model definition.

public class MyClass {
    private ClassWithSameName classOne;
    private subpackge.ClassWithSameName classTwo;

    // getters and setters
}

There will only be one generated Schema for ClassWithSameName and both properties point to the same definition. Same problem for enums when they are resolved as refs.
I'm aware of useFqn in TypeNameResolver but this setting affects all names. I'd prefer a solution where the name is only changed in case of a collision.

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

Start with TypeNameResolver and the model-definition path that resolves class and enum references. Reproduce the case with same simple names in different packages, then trace how schemas and refs are assigned. Done means colliding names receive distinct definitions while non-colliding names retain their existing naming behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.