OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] Inner Enum generation with BigDecimal values results in compilation error
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
Hello,
I recently updated openapi-generator-maven-plugin from Version 7.9.0 to 7.10.0. The new version seems to have problems when generating inner enums with BigDecimal fields. The generated Code produces compiler errors, because it tries to create instances of BigDecimal with
BigDecimal.valueOf(new BigDecimal("0"))
BigDecimals valueOf method has no such singnature.
openapi-generator version
Version 7.10.0
Generation Details
The maven configuration of the generator plugin looks like this:
<configuration>
<inputSpec>target/generated-sources/openapi/inputspec.yml</inputSpec>
<output>target/generated-sources</output>
<generatorName>spring</generatorName>
<generateApis>true</generateApis>
<generateSupportingFiles>true</generateSupportingFiles>
<typeMappings>
<typeMapping>Double=java.math.BigDecimal</typeMapping>
</typeMappings>
<configHelp>false</configHelp>
<configOptions>
<basePackage>${genclasses.package}</basePackage>
<apiPackage>${genclasses.package}.api</apiPackage>
<modelPackage>${genclasses.package}.model</modelPackage>
<dateLibrary>java8</dateLibrary>
<library>spring-boot</library>
<useSpringBoot3>true</useSpringBoot3>
<useJakartaEe>true</useJakartaEe>
<interfaceOnly>true</interfaceOnly>
<serializableModel>false</serializableModel>
<skipDefaultInterface>true</skipDefaultInterface>
<skipIfSpecIsUnchanged>true</skipIfSpecIsUnchanged>
<snapshotVersion>true</snapshotVersion>
<useTags>true</useTags>
</configOptions>
</configuration>
Generated Output
With version 7.9.0 the inner enums are looking good:
public enum TypeEnum {
NUMBER_0(new BigDecimal("0")),
NUMBER_1(new BigDecimal("1")),
NUMBER_2(new BigDecimal("2"));
private BigDecimal value;
TypeEnum(BigDecimal value) {
this.value = value;
}
// ... more code
}
Version 7.10.0 produces:
public enum TypeEnum {
NUMBER_0(BigDecimal.valueOf(new BigDecimal("0"))),
NUMBER_1(BigDecimal.valueOf(new BigDecimal("1"))),
NUMBER_2(BigDecimal.valueOf(new BigDecimal("2")));
private BigDecimal value;
TypeEnum(BigDecimal value) {
this.value = value;
}
// ... more code
}
Suggest a fix
I found this PR PR-19815 which seems to introduce the issue. The template file modules/openapi-generator/src/main/resources/Java/modelInnerEnum.mustache:26 now defines to use the .valueOf method, which doesn't work for type BigDecimal if the argument also is a BigDecimal.
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 modules/openapi-generator/src/main/resources/Java/modelInnerEnum.mustache and compare the change introduced by PR-19815 with the 7.9.0 output shown in the issue. Reproduce generation for the BigDecimal inner enum, then verify the generated Java compiles without passing a BigDecimal to BigDecimal.valueOf.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100