swagger-api / swagger-api/swagger-codegen-generators
Wrong enum genertion if prefix_ are same
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
If we have enum that has same prefix followed it truncates the prefix from actual name
For e.g. if we have enum
public enum Descriptions {
DESCRIPTION_1,
DESCRIPTION_2,
DESCRIPTION_3;
}
Then it generates api code as below by truncating DESCRIPTION_. this causes issues with client as we do not get to access same enum value.
public enum Descriptions {
_1("DESCRIPTION_1"),
_2("DESCRIPTION_2"),
_3("DESCRIPTION_3");
private String value;
Descriptions(String value) {
this.value = value;
}
@JsonValue
public String getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
@JsonCreator
public static Descriptions fromValue(String value) {
for (Descriptions b : Descriptions.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides a Java enum example but names no source file or test. Start by reproducing the generated output with several enum values sharing a prefix, then locate the generator path responsible for converting enum names. Done means the generated constants remain uniquely accessible while retaining their original serialized values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100