Skip to content

[java-spring;kotlin-spring] fix values escaping - #24915

Draft
Picazsoo wants to merge 16 commits into
OpenAPITools:masterfrom
Picazsoo:bugfix/fix-values-escaping
Draft

[java-spring;kotlin-spring] fix values escaping#24915
Picazsoo wants to merge 16 commits into
OpenAPITools:masterfrom
Picazsoo:bugfix/fix-values-escaping

Conversation

@Picazsoo

@Picazsoo Picazsoo commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

OpenAPI values were being reused across incompatible output contexts: as raw specification data, already-escaped template text, documentation text, and Java/Kotlin source literals. This could double-escape values, alter their runtime meaning, generate invalid source, and, in some Kotlin annotation paths, allow a malicious specification value to terminate a generated string literal.

This PR introduces context-specific Java and Kotlin source/documentation escaping helpers and preserves raw value provenance where templates need it. Java Spring and Kotlin Spring templates now render OpenAPI text through the serializer required by each output context, including annotations, defaults, examples, enum wire values, paths, tags, and generated documentation.

It also corrects Spring form-default documentation: OpenAPI form-property defaults are labeled as OpenAPI schema defaults and generation logs a warning, because the generated Spring form binding does not apply them when a field is omitted.

Fixed issues

Scope and follow-up

This is an initial, focused fix for the Java Spring and Kotlin Spring generators. Similar raw-value/escaping problems exist in other generator families and output contexts, including Kotlin clients and kotlin-server; those are intentionally out of scope here.

The raw-value provenance and context-specific serializer approach established by this PR provides a reusable basis for addressing those cases after this change has been tested successfully in real-world specifications.

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

Fixes double-escaping of OpenAPI values in the Spring and Kotlin Spring generators. Values were previously escaped during model construction and again in templates, producing artifacts like <= and \"; they are now preserved raw and escaped once for their output context.

Bug Fixes

  • Adds Java and Kotlin source-literal and documentation helpers for all OpenAPI value contexts, including annotations, Javadocs, defaults, examples, paths, enum wire values, and info metadata.
  • Preserves UUID parameter serialization, stabilizes date-time defaults as full ISO-8601 offsets, and updates generated Spring samples.
  • Marks schema defaults that Spring form bindings cannot enforce as "OpenAPI schema default" in generated Javadocs.
  • Adds regression coverage; descriptions ending in whitespace may now produce an extra * line in generated Javadocs.

Written for commit 4e275de. Summary will update on new commits.

Review in cubic

Picazsoo and others added 7 commits September 8, 2026 09:53
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Picazsoo
Picazsoo marked this pull request as ready for review September 9, 2026 11:46
@Picazsoo
Picazsoo marked this pull request as draft September 9, 2026 11:47

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

Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.

Re-trigger cubic

Comment thread modules/openapi-generator/src/main/resources/kotlin-spring/formParams.mustache Outdated
Comment thread modules/openapi-generator/src/main/resources/kotlin-spring/pathParams.mustache Outdated
Comment thread modules/openapi-generator/src/main/resources/kotlin-spring/cookieParams.mustache Outdated
Comment thread modules/openapi-generator/src/main/resources/kotlin-spring/apiController.mustache Outdated
Picazsoo and others added 2 commits September 9, 2026 14:23
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Picazsoo
Picazsoo marked this pull request as ready for review September 9, 2026 12:56
@Picazsoo
Picazsoo marked this pull request as draft September 9, 2026 12:57

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

Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.

Re-trigger cubic

Comment thread modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Picazsoo
Picazsoo marked this pull request as ready for review September 9, 2026 13:29
@Picazsoo
Picazsoo marked this pull request as draft September 9, 2026 13:29

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

Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.
Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

Re-trigger cubic

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Picazsoo
Picazsoo marked this pull request as ready for review September 9, 2026 14:07
@Picazsoo
Picazsoo marked this pull request as draft September 9, 2026 14:07

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

Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.

Re-trigger cubic

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Picazsoo
Picazsoo marked this pull request as ready for review September 9, 2026 15:48
@Picazsoo
Picazsoo marked this pull request as draft September 9, 2026 15:49

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

Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.
Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

Re-trigger cubic

@Picazsoo Picazsoo changed the title Bugfix/fix values escaping [java-spring;kotlin-spring] fix values escaping Sep 9, 2026
@Picazsoo
Picazsoo marked this pull request as ready for review September 9, 2026 16:25

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

Note: This PR contains a large number of files. cubic selects up to 200 of the highest-priority eligible files for this review, so some files may not have been reviewed.

Re-trigger cubic

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

1 issue found across 115 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java">

<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java:4538">
P2: The new DiscriminatorParent assertion expects source `name = "kind$\"\\name"` (two backslash chars before `name`), but the YAML mapping key `'kind$\"\\name'` contains two literal backslashes, and `kotlinStringLiteral` escapes each backslash as `\\` (as the FormFeed assertion in the same file confirms). Correct escaping would produce four backslashes, so either this assertion would fail against correct generator output, or the generated discriminator mapping silently drops a backslash. Verify the actual rendered source and align the assertion with the true YAML value.</violation>
</file>

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

Re-trigger cubic

"java.net.URI.create(\"https://example.test/\\$uri\")");
assertFileContains(controllerFiles.get("DiscriminatorParent.kt").toPath(),
"property = \"\\$kind\"",
"name = \"kind\\$\\\"\\\\name\"",

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.

P2: The new DiscriminatorParent assertion expects source name = "kind$\"\\name" (two backslash chars before name), but the YAML mapping key 'kind$\"\\name' contains two literal backslashes, and kotlinStringLiteral escapes each backslash as \\ (as the FormFeed assertion in the same file confirms). Correct escaping would produce four backslashes, so either this assertion would fail against correct generator output, or the generated discriminator mapping silently drops a backslash. Verify the actual rendered source and align the assertion with the true YAML value.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java, line 4538:

<comment>The new DiscriminatorParent assertion expects source `name = "kind$\"\\name"` (two backslash chars before `name`), but the YAML mapping key `'kind$\"\\name'` contains two literal backslashes, and `kotlinStringLiteral` escapes each backslash as `\\` (as the FormFeed assertion in the same file confirms). Correct escaping would produce four backslashes, so either this assertion would fail against correct generator output, or the generated discriminator mapping silently drops a backslash. Verify the actual rendered source and align the assertion with the true YAML value.</comment>

<file context>
@@ -4532,7 +4532,13 @@ public void kotlinSourceLiteralsEscapePathsContextPathsAndOAuthAnnotations() thr
+                "java.net.URI.create(\"https://example.test/\\$uri\")");
+        assertFileContains(controllerFiles.get("DiscriminatorParent.kt").toPath(),
+                "property = \"\\$kind\"",
+                "name = \"kind\\$\\\"\\\\name\"",
+                "name = \"mapping\\$\\\"\\\\name\"");
+        assertFileContains(controllerFiles.get("DiscriminatorChild.kt").toPath(),
</file context>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be a false positive. The actual YAML key 'kind$"\name' contains one literal backslash. That becomes two in generated Kotlin source, represented by four in the Java test string. The assertion is correct; no backslash is lost.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@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 7 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@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 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Picazsoo
Picazsoo marked this pull request as draft September 10, 2026 16:06
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] Operation Description Escapes Generated Annotation String and Injects a Spring Handler

1 participant