fix #17793 [JAVA] regressions introduced by #17622 (lombok)

Merged
DA
1mo ago
+455-43

This PR fix the issue @17793, item 1 and 2 from @jasper-vandemalle.

I found a better spec file at modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml, it contains rich model definitions than default pet store yaml, such as additional annotation of @JsonProperty, @Schema, @Size. , also array with minItems and x-setter-extra-annotation, i updated example samples/server/petstore/springboot-lombok-tostring to use this spec file and now user can review the output java file after use @lombok in additionalModelTypeAnnotations.

The code change is main on modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java, split the lombok.Data into atomic tags, and update modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache to include fields that legacy exists.

@wing328 @martin-mfg @cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes regressions from #17622 that broke Java Spring model generation when @lombok.Data is set in additionalModelTypeAnnotations. Lombok models were losing field-level annotations like bean validation, @Schema, and @JsonProperty.

Bug Fixes

  • AbstractJavaCodegen expands @lombok.Data into its atomic tags (Getter, Setter, ToString, EqualsAndHashCode, RequiredArgsConstructor).
  • lombokAnnotation.mustache restores field-level annotations, extra annotations, and bean validation for Lombok models.
  • additionalProperties.mustache suppresses the Lombok setter for the additionalProperties map so custom setters keep working.
  • pojo.mustache normalizes template indentation.
  • Adds equivalence tests covering OpenAPI 3.0/3.1 petstore, validation-attributes, and spring petstore-with-fake-endpoints specs, and regenerates affected samples.