Skip to content

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

Open
Ignacio-Vidal wants to merge 1 commit into
OpenAPITools:masterfrom
Ignacio-Vidal:jaxrs-spec-email
Open

[jaxrs-spec] Emit @Email bean validation for string with format: email#24271
Ignacio-Vidal wants to merge 1 commit into
OpenAPITools:masterfrom
Ignacio-Vidal:jaxrs-spec-email

Conversation

@Ignacio-Vidal

@Ignacio-Vidal Ignacio-Vidal commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

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.

Written for commit aecbe3d. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

The jaxrs-spec generator recognised format: email (isEmail was already set
in DefaultCodegen) but its beanValidationCore.mustache never consumed the
flag, so email fields and parameters were generated with no validation,
unlike the Spring generator.

Emit @Email from beanValidationCore.mustache when isEmail is set. No new
import is needed: model.mustache and api.mustache already declare the
wildcard import {javaxPackage}.validation.constraints.*, so the correct
javax/jakarta package is selected automatically. The annotation carries a
trailing space so the marker annotation does not abut the following getter
modifier (e.g. '@Email public'), and is only reached under
useBeanValidation, matching @Pattern/@SiZe.

Expanded the shared issue_4876_format_email.yaml fixture with a required
format: email query parameter and added unit tests covering model
properties and parameters across javax, jakarta, and the disabled case.

Added format: email properties (one required, one optional) to the
required-and-readonly-property sample spec and regenerated the
jaxrs-spec-required-and-readonly-property sample, so the generated @Email
output is committed and verified by CI. The sample compiles.
@Ignacio-Vidal Ignacio-Vidal changed the title [jaxrs-spec] Add @Email bean validation for format: email strings [jaxrs-spec] Emit @Email bean validation for string with format: email Jul 10, 2026
@Ignacio-Vidal

Copy link
Copy Markdown
Contributor Author

@wing328 - could you review this small PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant