OpenAPITools / OpenAPITools/openapi-generator
[BUG][JavaSpring] wrong parsing of space separated lombok annotations
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?
Description
Starting with Version 7.6.0 the lombok Annotation @NoArgsConstructor collides with a generated default constructor since the pojo.mustache for JavaSpring was changed with https://github.com/OpenAPITools/openapi-generator/pull/18650 and the inverted Section {{^lombok.NoArgsConstructor}} surrounding the template for the default constructor was removed. The PR and the Release Notes seem to not contain any infos regarding this change, which led me to the hypothesis this change might have been unintentional.
actual output: a pojo with a default constructor and the lombok annotation @NoArgsConstructor added that does not compile
expected output: a pojo with no default constructor and the lombok annotation @NoArgsConstructor added that does compile
openapi-generator version
7.6.0
OpenAPI declaration file content or url
Issue does not seem to be dependent on details of YAML
Generation Details
openapi-maven-generator-plugin version 7.6.0 was used to generate - relevant to the issue at hand is adding @lombok.NoArgsConstructor via <additionalModelTypeAnnotations>.
<configuration>
<inputSpec>${kontrakte.dir}/contract.yaml</inputSpec>
<generatorName>spring</generatorName>
<generateApis>true</generateApis>
<generateModels>true</generateModels>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<generateModelDocumentation>false</generateModelDocumentation>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<additionalProperties>removeEnumValuePrefix=false</additionalProperties>
<configOptions>
<useSpringBoot3>true</useSpringBoot3>
<useTags>true</useTags>
<sourceFolder>src/gen/java</sourceFolder>
<serializableModel>true</serializableModel>
<dateLibrary>java8-localdatetime</dateLibrary>
<delegatePattern>true</delegatePattern>
<!--suppress UnresolvedMavenProperty -->
<additionalModelTypeAnnotations>
@lombok.Builder @lombok.NoArgsConstructor @lombok.AllArgsConstructor
</additionalModelTypeAnnotations>
<generatedConstructorWithRequiredArgs>false</generatedConstructorWithRequiredArgs>
</configOptions>
</configuration>
Steps to reproduce
Use openapi-generator-maven-plugin in version 7.6.0 with the above to generate artifacts. The generated Pojo does not compile.
After downgrading the plugin to version 7.5.0 the problem is resolved. No default constructor is generated that collides with the Lombok-Annotation. The generated Pojo compiles.
Related issues/PRs
I checked all issues created since the release of version 7.6.0 and did not find any already adressing this problem.
Suggest a fix
Re-adding the removed inverted section {{^lombok.NoArgsConstructor}} around the template for the default constructor should resolve this issue.
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 JavaSpring pojo.mustache template and review the constructor-related change from pull request 18650. Reproduce the issue with the openapi-maven-generator-plugin configuration in the report, then verify that a model using @lombok.NoArgsConstructor no longer receives a colliding generated default constructor and compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100