swagger-api / swagger-api/swagger-core
Jackson enum value is not used if @JsonValue is on an interface method
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 7.5k
- Forks
- 2.3k
- Avg merge
- 18h 1m
- Merged PRs (30d)
- 10
Description
When Jackson's @JsonValue is used on an enum method, the Swagger enum list properly uses this value. However, when it is used on an interface method which is implemented by the enum, the Swagger enum list does not. This causes a discrepancy between what the REST API actually accepts (as defined by Jackson) and what the Swagger definition states it does.
To verify the behavior, update the JacksonValueEnum in the swagger-core test. The EnumPropertyTest.testExtractJacksonEnumFields test will then fail.
Custom enum interface:
public interface CustomEnum {
@JsonValue
String getValue();
}
Updated enum to implement the interface:
public enum JacksonValueEnum implements CustomEnum {
FIRST("one"),
SECOND("two"),
THIRD("three"),
@Hidden HIDDEN("hidden");
private final String value;
JacksonValueEnum(String value) {
this.value = value;
}
@Override
public String getValue() {
return 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
Start with modules/swagger-core/src/test/java/io/swagger/v3/core/oas/models/JacksonValueEnum.java and reproduce the interface-based @JsonValue case described in the issue. Run EnumPropertyTest.testExtractJacksonEnumFields in modules/swagger-core/src/test/java/io/swagger/v3/core/converting/EnumPropertyTest.java and trace the enum extraction behavior it exercises. Done means the test passes and the Swagger enum list matches the values accepted by Jackson.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100