swagger-api / swagger-api/swagger-codegen

Trying to generate Map<String, enum>

Open
#2,600 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi

Swagger-codegen: 2.1.6
Language: Java

I'm trying to generate Map<String, enum> from .json files:

{
    "required": [
        "myfield"
    ],
    "properties": {
        "myfield": {
            "type": "object",
            "additionalProperties": {
                "type": "string",
                "enum": [
                    "HOME",
                    "WORK"
                ]
            }
        }
    }
}

I'm expecting something like this:


  public enum MyfieldEnum {
     HOME, WORK
  }

  private Map<String, String> myfield = new HashMap<String, MyfieldEnum>();

But the generated code ends up like this:

  private Map<String, String> myfield = new HashMap<String, String>();

Is what I'm trying to do possible at all?

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 by reproducing the Java generation with Swagger-codegen 2.1.6 and the provided JSON schema, then trace how additionalProperties enums are handled in the Java generator. Done means establishing whether Map values can use a generated enum and, if so, identifying the generator area that must change; no file or test is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.