[KOTLIN-ALL-GENS] - fix escaping of values across all templates#23633
[KOTLIN-ALL-GENS] - fix escaping of values across all templates#23633Picazsoo wants to merge 9 commits intoOpenAPITools:masterfrom
Conversation
# Conflicts: # modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java
There was a problem hiding this comment.
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.
| @@ -0,0 +1,49 @@ | |||
| /** | |||
There was a problem hiding this comment.
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>
…JacksonSerialization) from the legacy kotlin package class into the canonical kotlin.spring package class
|
can you please review the build failures when you've time? cc @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10) @dennisameling (2026/02) |
|
absolutely will do ASAP. I realize this is a pretty big PR, but it should solve a lot of issues. If I cannot solve it across the board, I might open a smaller one focusing just on some kotlin generators first. |
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 asdollar, 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
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)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 and docs, adds a worst‑case spec, regenerates samples, and expands/migrates tests (fixes #20502).
Bug Fixes
lambda.escapeInNormalString,lambda.escapeDollarInMultiline, andlambda.escapeMarkdown.unescapedDefaultValuefields; respect enums and multiline strings.CodegenOperation.unescapedSummary,CodegenResponse.unescapedMessage,CodegenParameter.unescapedDefaultValue,CodegenProperty.unescapedDefaultValue.kotlin-jvm-retrofit2, validate/sanitize@Pathnames and emitvendorExtensions.x-retrofit-path-name; extract the validation regex into a reusablePattern.@JsonPropertynames for Jackson; update client/server templates (OkHttp,Retrofit2,Ktor,WebClient/RestClient,Spring,Javalin,JAX‑RS,Vert.x,Misk,WireMock) and docs to use markdown‑safe text and consistent parameter tables.issue20502-kotlin-string-escaping.yaml), newecho_apisamples forkotlin-jvm-okhttpandkotlin-jvm-spring-3-restclient, and additional unit tests covering Kotlin Spring server, Retrofit2 path‑name sanitization, and Jackson@JsonPropertyescaping. Migrate two Kotlin Spring server tests (gradle wrapper, polymorphic Jackson) into the canonical suite. Update Misk configs to usepetstore-kotlin-misk.yaml.Migration
{{#lambda.escapeInNormalString}}...{{/lambda.escapeInNormalString}},{{#lambda.escapeDollarInMultiline}}...{{/lambda.escapeDollarInMultiline}},{{#lambda.escapeMarkdown}}...{{/lambda.escapeMarkdown}}, and{{#lambda.removeLineBreak}}...{{/lambda.removeLineBreak}}. Replace old keys likelambdaEscapeInNormalString/lambdaRemoveLineBreak. Regenerate code.Written for commit 8c51a1c. Summary will update on new commits. Review in cubic