Skip to content

[KOTLIN-ALL-GENS] - fix escaping of values across all templates#23633

Open
Picazsoo wants to merge 5 commits intoOpenAPITools:masterfrom
Picazsoo:feature/fix-values3
Open

[KOTLIN-ALL-GENS] - fix escaping of values across all templates#23633
Picazsoo wants to merge 5 commits intoOpenAPITools:masterfrom
Picazsoo:feature/fix-values3

Conversation

@Picazsoo
Copy link
Copy Markdown
Contributor

@Picazsoo Picazsoo commented Apr 27, 2026

This PR fixes many issues with incorrect escaping of default values, examples, descriptions in various contexts (as string literals, as kdocs, as multiline docs, as single line docs, as inline docs). The biggest issue of these was the default value that practically affects implementation logic and it was often incorrectly escaped. E.g. $ symbol was sometimes escaped as dollar, sometimes it was not escaped at all, leading to issues with compilation.

commits until e14fdba apply the fix to the existing sample configs as-is. The next commit includes a stress-test for the generated samples on purpose by extending the various open api specs with difficult-to-process values full of tricky defaults/examples/descriptions as well as problematic attribute names.

I am not 100% sure that this fixes everything everywhere, but I think it is a move in the right direction for the kotlin codegens

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • 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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • 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 incorrect escaping across all Kotlin templates to prevent invalid Kotlin code and broken docs. Centralizes escaping with new Mustache lambdas and unescaped fields; updates templates, aligns parameter tables in docs, adds worst‑case spec, regenerates samples, and adds tests (fixes #20502).

  • Bug Fixes

    • Escape Kotlin strings in paths, param/base names, headers/cookies, annotations, and WireMock URLs using lambda.escapeInNormalString, lambda.escapeDollarInMultiline, and lambda.escapeMarkdown.
    • Correct string default values via new unescapedDefaultValue fields and lambda.escapeInNormalString; respects enums and multiline strings.
    • Add unescaped fields: CodegenOperation.unescapedSummary, CodegenResponse.unescapedMessage, CodegenParameter.unescapedDefaultValue, CodegenProperty.unescapedDefaultValue.
    • For kotlin-jvm-retrofit2, validate/sanitize @Path names and emit vendorExtensions.x-retrofit-path-name to avoid invalid Retrofit placeholders.
    • Update kotlin-client and server templates (OkHttp, Retrofit2, Ktor, WebClient/RestClient, Spring, Javalin, JAX‑RS, Vert.x, Misk, WireMock), including @JsonProperty names and annotation strings; fix API docs to use markdown‑safe texts and consistent parameter tables.
    • Add worst‑case OpenAPI spec (issue20502-kotlin-string-escaping.yaml), new echo_api samples for kotlin-jvm-okhttp and kotlin-jvm-spring-3-restclient, and tests covering $, backslashes, quotes, and comment markers. Update Misk configs to use petstore-kotlin-misk.yaml.
  • Migration

    • For custom templates, use new lambdas: {{#lambda.escapeInNormalString}}...{{/lambda.escapeInNormalString}}, {{#lambda.escapeDollarInMultiline}}...{{/lambda.escapeDollarInMultiline}}, {{#lambda.escapeMarkdown}}...{{/lambda.escapeMarkdown}}, and {{#lambda.removeLineBreak}}...{{/lambda.removeLineBreak}}. Replace old keys like lambdaEscapeInNormalString / lambdaRemoveLineBreak. Regenerate code.

Written for commit 67ee557. Summary will update on new commits. Review in cubic

@Picazsoo Picazsoo marked this pull request as ready for review April 27, 2026 14:49
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 120 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed. cubic prioritises the most important files to review.

# Conflicts:
#	modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

7 issues found across 81 files (changes from recent commits).

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed. cubic prioritises the most important files to review.

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="samples/client/echo_api/kotlin-jvm-spring-3-restclient/docs/EchoApi.md">

<violation number="1" location="samples/client/echo_api/kotlin-jvm-spring-3-restclient/docs/EchoApi.md:40">
P2: Parameters table is malformed: a data row is emitted before the header/separator, which can break Markdown rendering and hide parameter metadata.</violation>
</file>

<file name="samples/client/echo_api/kotlin-model-prefix-type-mappings/docs/EchoApi.md">

<violation number="1" location="samples/client/echo_api/kotlin-model-prefix-type-mappings/docs/EchoApi.md:33">
P2: Parameters table is malformed: a data row is emitted before the header row, which can break or confuse Markdown rendering.</violation>
</file>

<file name="samples/client/echo_api/kotlin-jvm-spring-3-webclient/docs/EchoApi.md">

<violation number="1" location="samples/client/echo_api/kotlin-jvm-spring-3-webclient/docs/EchoApi.md:40">
P2: Parameters table is malformed because a data row appears before the table header and separator.</violation>
</file>

<file name="samples/client/echo_api/kotlin-jvm-okhttp/docs/EchoApi.md">

<violation number="1" location="samples/client/echo_api/kotlin-jvm-okhttp/docs/EchoApi.md:40">
P2: Parameters table is malformed because a data row is emitted before the header/separator, which can break rendering and omit the first parameter.</violation>
</file>

<file name="samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:94">
P2: Adapter registration is performed after Retrofit’s Gson converter is created, so this newly added model adapter is not applied in this constructor path.</violation>
</file>

<file name="samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/apis/EchoApi.kt">

<violation number="1" location="samples/client/echo_api/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/apis/EchoApi.kt:22">
P2: Retrofit path placeholder name contains `$`, which violates Retrofit’s `@Path` name regex and can cause service method parsing to fail at runtime.</violation>
</file>

<file name="samples/client/echo_api/kotlin-jvm-okhttp/src/test/kotlin/org/openapitools/client/models/StringEscapingEdgeCasesTest.kt">

<violation number="1" location="samples/client/echo_api/kotlin-jvm-okhttp/src/test/kotlin/org/openapitools/client/models/StringEscapingEdgeCasesTest.kt:1">
P2: String-escaping regression test is a no-op because all assertions are commented out, so it cannot catch the escaping bugs it is meant to cover.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread samples/client/echo_api/kotlin-jvm-spring-3-restclient/docs/EchoApi.md Outdated
Comment thread samples/client/echo_api/kotlin-model-prefix-type-mappings/docs/EchoApi.md Outdated
Comment thread samples/client/echo_api/kotlin-jvm-spring-3-webclient/docs/EchoApi.md Outdated
Comment thread samples/client/echo_api/kotlin-jvm-okhttp/docs/EchoApi.md Outdated
@@ -0,0 +1,49 @@
/**
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 27, 2026

Choose a reason for hiding this comment

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

P2: String-escaping regression test is a no-op because all assertions are commented out, so it cannot catch the escaping bugs it is meant to cover.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/kotlin-jvm-okhttp/src/test/kotlin/org/openapitools/client/models/StringEscapingEdgeCasesTest.kt:

<comment>String-escaping regression test is a no-op because all assertions are commented out, so it cannot catch the escaping bugs it is meant to cover.</comment>

<file context>
@@ -0,0 +1,49 @@
+/**
+ *
+ * Please note:
+ * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
+ * Do not edit this file manually.
+ *
+ */
+
+@file:Suppress(
</file context>
Fix with Cubic

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] properties title name "$and" getting compile error

1 participant