fix(kotlin-spring): omit `@Pattern` and `@Size` for URI values
Fixes #25751
The Kotlin Spring generator emits @Pattern or @Size for URI model properties and operation parameters when the corresponding pattern, minLength, or maxLength constraint is set. These values are generated as java.net.URI, which is not supported by Bean Validation's @Pattern or @Size constraints and can cause validation failures.
This change omits string-based @Pattern and @Size annotations for URI model properties and parameters. The generator also marks URI parameters accordingly so the parameter validation template can apply the same guards. Constraints on regular string values and collection sizes remain unchanged.
Similar Java generator fix: #18095, #18135
Kotlin technical committee: @karismann @Zomzog @andrewemery @4brunu @stefankoppier @e5l @AndreyVMarkelov
Verification
- Focused regression test:
KotlinSpringServerCodegenTest#uriPropertiesAndParametersDoNotGetPatternOrSizeConstraints— passed (1 test, 0 failures). It coversminLengthonly,maxLengthonly, and both length constraints for URI model properties and query parameters, while confirming regular strings retain the matching@Sizeconstraints. ./mvnw clean package, full sample generation, and documentation export passed before the AI review follow-ups. The focused test above passed after the latest changes.
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
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 targets a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Summary by cubic
Fixes #25751. The Kotlin Spring generator now omits @Pattern and @Size constraints on format: uri properties and parameters, which are generated as java.net.URI and aren't supported by Bean Validation's @Pattern and @Size annotations, so previously generated code was invalid.
Adds isUri guards to the pattern and string-length branches in beanValidationCore.mustache and beanValidationModel.mustache, backed by a regression test covering minLength, maxLength, and both variants. Regular string properties and collection size constraints are unaffected, and URI parameters are marked via updateParameterForString.