swagger-api / swagger-api/swagger-codegen
[JAVA] swagger-codgen generates code with syntax error in Enum when defined in separate definition file
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Swagger-codegen version
3.0.30
Swagger declaration file content or url
Command line used for generation
swagger-codegen generate -i ./api.yml -l java -o ./generated-code
Steps to reproduce
- Keep the files api.yml, base-definitions.json and consumer.json in some directory
swagger-codegen generate -i ./api.yml -l java -o ./generated-code- cd generated code
- mvn clean install
Related issues/PRs
Suggest a fix/enhancement
The category definitions in base-definitions.json file produces errors in read method generated in Cateogory.java
@Override
public Category read(final JsonReader jsonReader) throws IOException {
Object value = jsonReader.nextString();
return Category.fromValue(()(value));
}
This seems to be a bug in codegen. The fix would be just to typecast the object to string i.e. generate the code as follows -
return Category.fromValue((String)(value));
Note: If we directly inline the enum inside some property instead of referring to external file definition, the issue doesn't happen and the inner class enum compiles successfully.
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 api.yml, base-definitions.json, and consumer.json, then run the documented swagger-codegen command and inspect the generated Category.java. Build the generated project with mvn clean install and compare the external-definition enum's read method with the working inline-enum case; done means the generated Java compiles without the reported syntax error.
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
- Clearly specified
- Newbie friendliness
- 45/100