swagger-api / swagger-api/swagger-codegen
Integer Enum in Array is not generated correctly in 3.0.7
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
There was very similar issue when generating Array of STRING Enums:
https://github.com/swagger-api/swagger-codegen/issues/7377
In 3.0.7 Swagger-Codegen version with 1.0.7 Swagger-Codegen-Generators the List is generated correctly for String type of Enum, but not for Integer type.
If I specify type of enum "integer" or "number", the enum values in Java Class still are generated as String values. See below
If I specify enum in yaml:
TbProductFilter:
type: object
properties:
productType:
type: array
items:
type: integer
enum:
- 0
- 1
- 2
- 3
Enum in Java Class:
public enum ProductTypeEnum {
_0("0"),
_1("1"),
_2("2"),
_3("3");
private Integer value;
ProductTypeEnum(Integer value) {
this.value = value;
}
@Override
@JsonValue
public String toString() {
return String.valueOf(value);
}
@JsonCreator
public static ProductTypeEnum fromValue(String text) {
for (ProductTypeEnum b : ProductTypeEnum.values()) {
if (String.valueOf(b.value).equals(text)) {
return b;
}
}
return null;
}
}
@JsonProperty("productType")
@Valid
private List<ProductTypeEnum> productType = null;
And ofcourse the code doesn't compile - values are strings, but everywhere else Integers are expected.
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
Start with the provided OpenAPI YAML and inspect the generated Java ProductTypeEnum for the array property. Compare integer enum handling with the referenced string-enum issue and trace the generator templates or entry point responsible for Java enum values. Done means integer enum constants compile with integer values while preserving the expected generated behavior.
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