swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Enum Names Not Overriden with @JsonProperty

Open PeaceInColour opened this issue 8 years ago • 8 comments

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.

PeaceInColour avatar Mar 15 '18 19:03 PeaceInColour

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.

PeaceInColour avatar Mar 15 '18 19:03 PeaceInColour

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.

frantuma avatar Mar 16 '18 14:03 frantuma

fixed in #2796

frantuma avatar May 04 '18 13:05 frantuma

any workarounds for someone stuck in the old version

rabiori avatar Jun 27 '19 13:06 rabiori

@rabiori Ever find a workaround?

jlous avatar May 24 '20 08:05 jlous

I am also using the old version, can anyone suggest a workaround?

DeepakPatankar avatar Aug 11 '20 05:08 DeepakPatankar

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

jlous avatar Aug 13 '20 11:08 jlous

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.

ursvasan avatar Apr 22 '21 18:04 ursvasan