swagger-api / swagger-api/swagger-codegen
Trying to generate Map<String, enum>
Open
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
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 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