OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java] Error when using property of type boolean with enum
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Generating from a model with a boolean property wich contains enums results in code that contains compile errors. I know that this is a rather stupid OpenAPI description, but it is nonetheless valid (and I sadly can't change the input spec I have to use).
openapi-generator version
5.0.1
OpenAPI declaration file content or url
"test": {
"type": "boolean",
"description": "Test",
"example": true,
"enum": [
true,
false
]
}
This results in:
public enum Test{
TRUE("true"),
FALSE("false");
...
}
Which fails to compile:
error: incompatible types: String cannot be converted to Boolean
TRUE("true"),
Generation Details
Java with any library results in this issue.
Steps to reproduce
Have any model contain a boolean property with enum values.
Related issues/PRs
None
Suggest a fix
The expected outcome should be:
public enum Test{
TRUE(true),
FALSE(false);
...
}
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 generation with the supplied boolean enum property using the Java generator and inspect the generated Test enum. Compare the generated enum constructor arguments with the Boolean type, then verify that the generated Java compiles and uses true and false rather than quoted strings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100