swagger-api / swagger-api/swagger-codegen

JAX-RS Swagger codegen does not handle enum defined in external json file

Open
#4,123 1 comment 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

If an enum is added into external json file Swagger Codegen does not generate model correctly.
Example project: https://github.com/abhijith-prabhakar/swagger-ref-error-demo/blob/master/src/main/resources/v1/schema/title/title.json#L43

 "media_types": {
      "description": "different media types",
      "type": "array",
      "items" : {
        "type" : "string",
        "enum" : [ "application/pdf", "application/json" ]
      }
    },

Generated Code

/**
   * different media types
   */
  public enum List<MediaTypesEnum> {
    PDF("application/pdf"),

        JSON("application/json");
    private List<String> value;

    List<MediaTypesEnum>(List<String> value) {
      this.value = value;
    }

    @Override
    @JsonValue
    public String toString() {
      return String.valueOf(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 the external schema at src/main/resources/v1/schema/title/title.json#L43 in the linked example project and inspect the generated JAX-RS enum shown in the issue. Trace how Swagger Codegen handles the external JSON definition and compare the generated model with the schema. Done means an external enum inside an array generates a valid Java model with the expected enum values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.