[jaxrs-spec] Emit @Email bean validation for string with format: email#24271
Open
Ignacio-Vidal wants to merge 1 commit into
Open
[jaxrs-spec] Emit @Email bean validation for string with format: email#24271Ignacio-Vidal wants to merge 1 commit into
Ignacio-Vidal wants to merge 1 commit into
Conversation
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.
83bb65b to
aecbe3d
Compare
3 tasks
Contributor
Author
|
@wing328 - could you review this small PR? |
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 jaxrs-spec server generator so thattype: string/format: emailproperties and parameters are validated at runtime, matching the behaviour already provided by the Spring generator.Background
DefaultCodegenalready setsisEmail = trueforformat: emailschemas across every Java generator, but jaxrs-spec'sbeanValidationCore.mustachenever consumed the flag. As a result email fields/parameters were emitted as a plainStringwith no@Emailconstraint (documentation-only), unlike Spring which renders@Email.Change
@EmailwhenisEmailis set underuseBeanValidationjavax/jakartapackage is selected automatically (including underuseJakartaEe=true).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 jaxrs-spec server generator fortype: stringwithformat: emailso models and query params are validated at runtime, matching Spring. Active only whenuseBeanValidationis enabled.New Features
@EmailwhenisEmailis set inbeanValidationCore.mustache.{{javaxPackage}}.validation.constraints.*forjavax/jakarta.Tests
issue_4876_format_email.yamlwith a requiredformat: emailquery parameter; added tests forjavax,jakarta, and disableduseBeanValidation.required-and-readonly-property.yamland regenerated thejaxrs-spec-required-and-readonly-propertysample with required/optional email fields to verify@Emailoutput compiles.Written for commit aecbe3d. Summary will update on new commits.