Skip to content

fix(kotlin-spring): omit @Pattern and @Size for URI values - #25752

Open
c19yamamoto wants to merge 6 commits into
OpenAPITools:masterfrom
c19yamamoto:fix-size-annotation-generate-for-java-uri
Open

c19yamamoto wants to merge 6 commits into
OpenAPITools:masterfrom
c19yamamoto:fix-size-annotation-generate-for-java-uri

Conversation

@c19yamamoto

@c19yamamoto c19yamamoto commented Nov 19, 2026 •

Copy link
Copy Markdown

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 covers minLength only, maxLength only, and both length constraints for URI model properties and query parameters, while confirming regular strings retain the matching @Size constraints.
  • ./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:
    ./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 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.

Written for commit 805cef7. Summary will update on new commits.

View guided diff

@c19yamamoto c19yamamoto changed the title fix(kotlin-spring): omit @Size for URI model properties fix(kotlin-spring): omit @Size for URI model properties Nov 19, 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.

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@c19yamamoto c19yamamoto changed the title fix(kotlin-spring): omit @Size for URI model properties fix(kotlin-spring): omit @Pattern and @Size for URI properties Nov 19, 2026
@c19yamamoto c19yamamoto changed the title fix(kotlin-spring): omit @Pattern and @Size for URI properties fix(kotlin-spring): omit @Pattern and @Size for URI properties Nov 19, 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.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@c19yamamoto c19yamamoto changed the title fix(kotlin-spring): omit @Pattern and @Size for URI properties fix(kotlin-spring): omit @Pattern and @Size for URI values Nov 19, 2026
@c19yamamoto
c19yamamoto marked this pull request as draft November 19, 2026 10:21
@c19yamamoto
c19yamamoto marked this pull request as ready for review November 19, 2026 10:21

@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.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@c19yamamoto
c19yamamoto marked this pull request as draft November 19, 2026 11:03
@c19yamamoto
c19yamamoto marked this pull request as ready for review November 19, 2026 11:03

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

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
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.

[BUG][KOTLIN-SPRING] @Size is generated for java.net.URI properties [REQ][JAVA] - [QA] How not to generate @Pattern and @Size for UUID

1 participant