Skip to content

[BUG][JavaSpring] wrong parsing of space separated lombok annotations #18868

Description

@gunnarkessler

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 #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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions