Skip to content

[BUG] issue with Spring required args constructor #14934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 of 6 tasks
borsch opened this issue Mar 12, 2023 · 1 comment
Closed
5 of 6 tasks

[BUG] issue with Spring required args constructor #14934

borsch opened this issue Mar 12, 2023 · 1 comment

Comments

@borsch
Copy link
Member

borsch commented Mar 12, 2023

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

After this change #14822 now when adding <additionalModelTypeAnnotations>@lombok.experimental.SuperBuilder</additionalModelTypeAnnotations> compilation might be broken

If object have some required parameters then everything works fine, but as soon as you have object without required parameters you are getting model where only "all args constructor" is present(generated by lombok) and there is no "no arg constructor"

Before this change I usually configured my models with <additionalModelTypeAnnotations>@lombok.AllArgsConstructor;@lombok.NoArgsConstructor;@lombok.experimental.SuperBuilder</additionalModelTypeAnnotations> so at the end I got "all args" & "no args" constructor generated by lombok

openapi-generator version

6.5.0-SNAPSHOT (not released yet)

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.5.0-SNAPSHOT</version>
				<configuration>
					<generateSupportingFiles>true</generateSupportingFiles>
					<modelNameSuffix>Dto</modelNameSuffix>
					<generateApiTests>false</generateApiTests>
					<generateModelTests>false</generateModelTests>
					<generateApiDocumentation>false</generateApiDocumentation>
					<configOptions>
						<interfaceOnly>true</interfaceOnly>
						<dateLibrary>java8</dateLibrary>
						<useTags>true</useTags>
						<openApiNullable>false</openApiNullable>
						<skipDefaultInterface>true</skipDefaultInterface>
						<documentationProvider>springfox</documentationProvider>
					</configOptions>
				</configuration>
				<executions>
					<execution>
						<id>generate-openapi-for-backend</id>
						<goals>
							<goal>generate</goal>
						</goals>
						<phase>generate-resources</phase>
						<configuration>
							<inputSpec>${project.basedir}/src/main/resources/contract/_index_auto.yaml</inputSpec>
							<generatorName>spring</generatorName>
							<configOptions>
								<additionalModelTypeAnnotations>@lombok.AllArgsConstructor;@lombok.NoArgsConstructor;@lombok.experimental.SuperBuilder</additionalModelTypeAnnotations>
							</configOptions>
						</configuration>
					</execution>
				</executions>
			</plugin>
Steps to reproduce
Related issues/PRs

#14822

Suggest a fix

add option generatedRequiredParametersConstructor=false. By default it should be false, because this new option will broke compilation as it's in my case

@alucas could you please implement this? Please ping if you have no time, then I can pick this one

@rvkhlystov
Copy link

rvkhlystov commented Oct 28, 2024

Broken generatedConstructorWithRequiredArgs for @lombok.NoArgsConstructor"

error: constructor TestRequest() is already defined in class CallbackRequest

id = "org.openapi.generator", version = "7.9.0"
"additionalModelTypeAnnotations" to "@lombok.AllArgsConstructor @lombok.NoArgsConstructor",
"generatedConstructorWithRequiredArgs" to "false"

This worked for version "7.3.0".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants