[Java][Spring] Do not generate required args constructor that duplicates @lombok.AllArgsConstructor
Description:
With the spring or java-camel generator and additionalProperties.lombok.AllArgsConstructor=true, a model whose properties are all required got two constructors with the same signature: the "Constructor with only required parameters" the generator writes, and the one Lombok adds for @lombok.AllArgsConstructor. The generated class did not compile (constructor ... is already defined).
In SpringCodegen.postProcessAllModels I now set a vendor extension on a model when @lombok.AllArgsConstructor is on and the generated required args constructor would have Lombok's signature. JavaSpring/pojo.mustache and java-camel-server/pojo.mustache skip that constructor when the extension is set. The no-args constructor stays.
The extension is only set when every own property is required and requiredVars.size() == vars.size(). requiredVars also holds inherited properties, so a model with a required parent property (Dog(String breed, String kind) vs. Lombok's Dog(String breed)) keeps its constructor. A nullable property with openApiNullable=true is a JsonNullable<T> field but a T parameter, so those models keep it too.
I added three tests in SpringCodegenTest plus 3_0/spring/issue_25395.yaml: the all-required case, the nullable case with openApiNullable=true, and the inherited case. The first and third fail without the change and pass with it. The nullable test passes either way and guards the case that must not change. samples/ has no diff.
Fixes #25395
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples (see below for what I ran instead):
./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
What I ran on this branch (macOS, Maven wrapper, offline after the first dependency download):
./mvnw -B -o -pl modules/openapi-generator -am test -Dtest='SpringCodegenTest#lombokAllArgs*'passes (3 tests). With the three source files put back to master, the all-required and inherited tests fail../mvnw -B -o -pl modules/openapi-generator -am test -Dtest=SpringCodegenTest,SpringPageableScanUtilsTest,SpringHttpStatusLambdaTest,JavaValidationArrayPrimitivesTestpasses (632 tests, 0 failures).- I generated the
springandjava-cameloutput for the fixture spec with and without the change and compiled it withjavacand Lombok. Master fails withconstructor Pet(Long,String) is already defined(and the same forAnimalandNicknamedPet). With the fix it compiles, also withopenApiNullable=true. ./bin/generate-samples.sh ./bin/configs/spring-boot-lombok-data.yamlexits 0 and leavessamples/unchanged. It is the only config that mentionsAllArgsConstructor.
I did not run the full ./mvnw clean package, the other sample configs, or ./bin/utils/export_docs_generators.sh, so the second box is unchecked. No option or docs text changed.
cc @cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg @KannaKim