[java][client] Emit @Email bean validation for string with format: email#24272
Open
Ignacio-Vidal wants to merge 1 commit into
Open
[java][client] Emit @Email bean validation for string with format: email#24272Ignacio-Vidal wants to merge 1 commit into
Ignacio-Vidal wants to merge 1 commit into
Conversation
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.
40e542b to
6c6c91b
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
@Emailbean-validation support to the java client generator so thattype: string/format: emailproperties and parameters are annotated with@Email, matching the behaviour in the Spring & jaxrs-spec generators (#24271).Background
DefaultCodegenalready setsisEmail = trueforformat: emailschemas across every Java generator, but the java client'sJava/beanValidationCore.mustachenever consumed the flag. As a result, withuseBeanValidation=true, an email field/parameter received@NotNull/@Size/@Patternwhere applicable but never@Email— the validation was silently dropped.Change
javax/jakartapackage is selected automatically due to import setup in the templatesuseBeanValidation, consistent with the existing constraints and is inherited b all libraries (native, jersey2/3, resttemplate, restclient, webclient, okhttp-gson, feign, retrofit2, microprofile)PR checklist
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.
Summary by cubic
Adds
@Emailbean validation to the Java client generator fortype: string/format: email. Email properties and parameters are now annotated whenuseBeanValidation=true.@EmailinJava/beanValidationCore.mustachewhenisEmailis set; applies to all Java client libraries underuseBeanValidation.jakarta.validation.constraints.*orjavax.validation.constraints.*are used.jakarta/javaxand the disabled case; regenerated theresttemplate-list-schema-validationsample with aUsermodel (and@Email) and updatedUserApito returnUseras JSON.Written for commit 6c6c91b. Summary will update on new commits.