swagger-api / swagger-api/swagger-codegen

[JAVA] Jackson innerEnum missing JsonValue symbol

Open
#8,724 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When using io.swagger:swagger-codegen-cli:2.3.1 from maven, get build issues for models with an inner enum. Specifically:

error: cannot find symbol
@JsonValue
   ^
symbol:   class JsonValue

Looking at the mustache file you can see the import is only in the modelEnum, yet the annotation is used in the modelInnerEnum template.

virt % grep -R  JsonValue ./Java
./Java/modelInnerEnum.mustache:    @JsonValue
./Java/modelEnum.mustache:import com.fasterxml.jackson.annotation.JsonValue;
./Java/modelEnum.mustache:  @JsonValue

The modelInnerEnum.mustache is expanded by the pojo.mustache template, both of which get their includes from model.mustache, which is also the top level for modelEnum.mustache.

Swagger-codegen version

From maven: io.swagger:swagger-codegen-cli:2.3.1

This seems to be a regression from io.swagger:swagger-codegen-cli:2.2.2 due to the added annotation.

Swagger declaration file content or url

JSON Model:

"FooObject" : {
      "type" : "object",
      "properties" : {
        "stringField" : {
          "type" : "string"
        },
        "enumField" : {
          "type" : "string",
          "enum" : [ "One", "Two", "Three", "Four", "Five" ]
        }
      }
    }
Command line used for generation

generate with a language using Java with jackson.

Steps to reproduce
  • Model with inner enum
  • Generate Java model with Jackson
  • Compile
Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/3611
https://github.com/swagger-api/swagger-codegen/issues/6587

Suggest a fix/enhancement

The imports from modelEnum should be moved into model to avoid the issue and be consistent with not having imports in pojo.mustache. Short of that add the imports to pojo.mustache.

So, basically integrate this: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Java/modelEnum.mustache#L1-L11

into here: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Java/model.mustache#L18

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-codegen/src/main/resources/Java/model.mustache, modelEnum.mustache, and modelInnerEnum.mustache, then generate a Java model with an inner enum using Jackson from the supplied schema. Compile the generated model and confirm the missing JsonValue symbol is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.