I use the swagger-codegen-maven-plugin to generate Java classes and have trouble with the getter of an entity class field / member which type is an enum. Until version 2.2.3 the getter returns the enum value but with all versions above the getter just returns String.
The field in question looks like follows in the swagger file:
"status": {
"type": "string",
"enum": [
"A",
"B",
"C",
"D",
"E",
"F",
"G"
]
},
Code generated for version until 2.2.3:
@XmlType(name="StatusEnum")
@XmlEnum(String.class)
public enum StatusEnum {
@XmlEnumValue("A") A(String.valueOf("A")), @XmlEnumValue("B") B(String.valueOf("B")), @XmlEnumValue("C") C(String.valueOf("C")), @XmlEnumValue("D") D(String.valueOf("D")), @XmlEnumValue("E") E(String.valueOf("E")), @XmlEnumValue("F") F(String.valueOf("F")), @XmlEnumValue("G") G(String.valueOf("G"));
private String value;
// omitted further details ...
}
/**
* Get status
* @return status
**/
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
Everything > 2.2.3 (tried 2.3.0, 2.4.0, 3.0.34):
public enum StatusEnum {
A("A"),
B("B"),
C("C"),
D("D"),
E("E"),
F("F"),
G("G");
private String value;
// omitted further details ...
}
/**
* Get status
* @return status
**/
@JsonProperty("status")
public String getStatus() {
if (status == null) {
return null;
}
return status.getValue();
}
public void setStatus(StatusEnum status) {
this.status = status;
}
How to configure the generator plugin to get the same method signature with version > 2.2.3 as before? Would be a lot of work to change the code in the existing projects everywhere where it calls getter of enum typed members.