[jaxrs-spec] Emit @Email bean validation for string with format: email

Merged
IG
4mo ago
+197-4

Adds @Email bean-validation support to the jaxrs-spec server generator so that type: string / format: email properties and parameters are validated at runtime, matching the behaviour already provided by the Spring generator.

Background

DefaultCodegen already sets isEmail = true for format: email schemas across every Java generator, but jaxrs-spec's beanValidationCore.mustache never consumed the flag. As a result email fields/parameters were emitted as a plain String with no @Email constraint (documentation-only), unlike Spring which renders @Email.

Change

  • emit @Email when isEmail is set under useBeanValidation
  • No new import is required — javax/jakarta package is selected automatically (including under useJakartaEe=true).

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 jaxrs-spec server generator for type: string with format: email so models and query params are validated at runtime, matching Spring. Active only when useBeanValidation is enabled.

  • New Features

    • Emit @Email when isEmail is set in beanValidationCore.mustache.
    • Uses existing wildcard import {{javaxPackage}}.validation.constraints.* for javax/jakarta.
    • Applies to models and query parameters; inherited by all jaxrs-spec libraries.
  • Tests

    • Expanded issue_4876_format_email.yaml with a required format: email query parameter; added tests for javax, jakarta, and disabled useBeanValidation.
    • Updated required-and-readonly-property.yaml and regenerated the jaxrs-spec-required-and-readonly-property sample with required/optional email fields to verify @Email output compiles.