Skip to content

[Java][Spring] Don't generate constructors if already there (with lombok) #15494

@Kilrath

Description

@Kilrath
Description

After this change #14822 now when adding

<additionalModelTypeAnnotations>
   @lombok.NoArgsConstructor <or>
   @lombok.ReqArgsConstructor <or>
   @lombok.AllArgsConstructor
</additionalModelTypeAnnotations> 

compilation might be broken due to an error like the constructor is already defined.

openapi-generator version
6.6.0

OpenAPI declaration file content or URL
any model with at least one property and there are no required properties

Generation Details

           <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>6.6.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${openapi.file}</inputSpec>
                            <generatorName>spring</generatorName>
                            <generateApiDocumentation>true</generateApiDocumentation>
                            <generateApis>true</generateApis>
                            <generateSupportingFiles>false</generateSupportingFiles>
                            <generateModelTests>false</generateModelTests>
                            <generatedConstructorWithRequiredArgs>false</generatedConstructorWithRequiredArgs>
                            <apiPackage>${project.artifactId}.infrastructure.api</apiPackage>
                            <modelPackage>${project.artifactId}.domain.model</modelPackage>
                            <skipIfSpecIsUnchanged>true</skipIfSpecIsUnchanged>
                            <languageSpecificPrimitives>String,int,boolean,Double</languageSpecificPrimitives>
                            <typeMappings>array=List,map=Map,string=String,integer=int,number=Double</typeMappings>
                            <configOptions>
                                <sourceFolder>src/main/java/</sourceFolder>
                                <interfaceOnly>true</interfaceOnly>
                                <skipDefaultInterface>true</skipDefaultInterface>
                                <requestMappingMode>api_interface</requestMappingMode>
                                <additionalModelTypeAnnotations>
                                    @lombok.Data
                                    @lombok.Builder
                                    @lombok.AllArgsConstructor
                                    @lombok.Generated
                                </additionalModelTypeAnnotations>
                                <dateLibrary>java8</dateLibrary>
                                <hateoas>false</hateoas>
                                <library>spring-boot</library>
                                <performBeanValidation>true</performBeanValidation>
                                <useOptional>true</useOptional>
                                <useSpringController>true</useSpringController>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Steps to reproduce
Related issues/PRs
#14822

Suggest a fix
Don't generate constructor if already exists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions