Skip to content

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

Open
Ignacio-Vidal wants to merge 1 commit into
OpenAPITools:masterfrom
Ignacio-Vidal:java-client-email
Open

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

Conversation

@Ignacio-Vidal

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

Copy link
Copy Markdown
Contributor

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.

Written for commit 6c6c91b. Summary will update on new commits.

Review in cubic

@Ignacio-Vidal Ignacio-Vidal changed the title [java][client] Add @Email bean validation for format: email strings [java][client] Emit @Email bean validation for string with format: email Jul 10, 2026

@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 11 files

Re-trigger cubic

The java client generator recognised format: email (isEmail was already set
in DefaultCodegen) but its beanValidationCore.mustache never consumed the
flag, so email properties and parameters were generated with no @Email
constraint, unlike the Spring generator.

Emit @Email from Java/beanValidationCore.mustache when isEmail is set,
matching the leading-space convention of the sibling @Pattern/@SiZe
annotations. No new import is needed: model.mustache and the microprofile
model template already declare the wildcard import
{javaxPackage}.validation.constraints.* / {rootJavaEEPackage}.validation.constraints.*,
so the correct javax/jakarta package is selected automatically. The
annotation is only reached under useBeanValidation.

Expanded the issue-17485 bean-validation fixture with a User model carrying
a required format: email property, added unit tests covering javax, jakarta
and the disabled case, and regenerated the resttemplate-list-schema-validation
sample so the generated @Email output is committed and verified by CI. The
sample compiles.
@Ignacio-Vidal

Copy link
Copy Markdown
Contributor Author

@wing328 - could you review this PR which is analogue to #24271?

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