Enum Names Not Overriden with @JsonProperty
| Q | A |
|---|---|
| Bug or feature request? | Bug |
| Which Swagger-Core version? | 1.5.18 |
| Which Java version? | 1.8u151 |
| Which JAX-RS framework & version? | RESTEasy 3.0.19 with JAX-RS 2.0 |
Using @JsonProperty to override enum names isn't working. The following example below:
public enum SomeEnum {
@JsonProperty("num-one")
NUMONE,
@JsonProperty("num-two")
NUMTWO
}
results in an OpenAPI file that looks like:
"enum": [
"NUMONE",
"NUMTWO"
]
instead of the expected:
"enum": [
"num-one",
"num-two"
]
The issue is in ModelResolver which is using the deprecated Jackson Databind method findEnumValue to read in the enum name. This method does not look for any overrides and just defaults to the name in the code. Using the replacement method findEnumValues fixes this problem.
Once I get permission to push (or figure out what's wrong if the issue is on my end) I can push a fix for this.
Thanks for the fix! to open a PR, please fork the repo and push the branch to your own repo, and open the PR from there targeting the main repo.
fixed in #2796
any workarounds for someone stuck in the old version
@rabiori Ever find a workaround?
I am also using the old version, can anyone suggest a workaround?
We used a custom ModelConverter on 2.x, which has a regression on this issue (fixed in 2.1.3) Don't know if that option applies to 1.5
I am using io.swagger:swagger-annotations 1.6.2 and i have the following
public enum Type
{
@JsonProperty("one")
ONE,
@JsonProperty("two")
TWO;
}
My spec only has
"enum": [
"ONE",
"TWO"
]
I am using io.swagger.core.v3: swagger-jaxrs2-servlet-initializer-v2 to generate the spec from the classes i have.