swagger-api / swagger-api/swagger-codegen
[Java] swagger-codegen-cli generates non-compiling Java files for enum in array
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When generating Java code from a Swagger file, the resulting Java code cannot be compiled before some (simple) hand editing. This is due to an enum being created using Integer, but the enum constructor being called with String.
The compiler error message is
java.lang.String cannot be converted to java.lang.Integer
Swagger-codegen version
I have tried 2.3.1, a snapshot of 2.4.0 from 2018-05-22 and master commit a4d6d7ba316232308e32ed4949e46f1bb3982d4a
Swagger declaration file content or url
JSON example at https://gist.github.com/JensCarlbergLiU/3bd3a37cb67c96f135ce1f30313f0fb0
Command line used for generation
java -jar swagger-codegen-cli.jar -i bug-swagger.json -l java
Steps to reproduce
java -jar swagger-codegen-cli.jar -i bug-swagger.json -l java
mvn compile
Related issues/PRs
I have searched for part of the error message: java.lang.String cannot be converted to java.lang.Integer
No hits, though.
Suggest a fix/enhancement
No sggestion beyond the obvious, sorry.
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 with the Swagger JSON example linked in the issue and reproduce generation using swagger-codegen-cli with the Java language, then run mvn compile on the generated project. Inspect the generated enum for the array case and compare its declared value type with the constructor argument. Done means the generated Java files compile without hand editing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100