[java][client] Emit @Email bean validation for string with format: email
Merged
IG
4mo ago+335+335+012345678901234567890123456789-14-14-01234567890123456789
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/jakartapackage 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:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
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
@EmailinJava/beanValidationCore.mustachewhenisEmailis set; applies to all Java client libraries underuseBeanValidation. - No import changes; existing wildcard imports
jakarta.validation.constraints.*orjavax.validation.constraints.*are used. - Added unit tests for
jakarta/javaxand the disabled case; regenerated theresttemplate-list-schema-validationsample with aUsermodel (and@Email) and updatedUserApito returnUseras JSON.
- Emit