[java][client] Emit @Email bean validation for string with format: email

Merged
IG
4mo ago
+335-14

Adds @Email bean-validation support to the java client generator so that type: string / format: email properties and parameters are annotated with @Email, matching the behaviour in the Spring & jaxrs-spec generators (#24271).

Background

DefaultCodegen already sets isEmail = true for format: email schemas across every Java generator, but the java client's Java/beanValidationCore.mustache never consumed the flag. As a result, with useBeanValidation=true, an email field/parameter received @NotNull/@Size/@Pattern where applicable but never @Email — the validation was silently dropped.

Change

  • No new import is required: javax/jakarta package is selected automatically due to import setup in the templates
  • The clause is only reached under useBeanValidation, consistent with the existing constraints and is inherited b all libraries (native, jersey2/3, resttemplate, restclient, webclient, okhttp-gson, feign, retrofit2, microprofile)

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

Adds @Email bean validation to the Java client generator for type: string / format: email. Email properties and parameters are now annotated when useBeanValidation=true.

  • New Features
    • Emit @Email in Java/beanValidationCore.mustache when isEmail is set; applies to all Java client libraries under useBeanValidation.
    • No import changes; existing wildcard imports jakarta.validation.constraints.* or javax.validation.constraints.* are used.
    • Added unit tests for jakarta/javax and the disabled case; regenerated the resttemplate-list-schema-validation sample with a User model (and @Email) and updated UserApi to return User as JSON.