swagger-api / swagger-api/swagger-core

Jackson enum value is not used if @JsonValue is on an interface method

Open
#4,466 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.