[KOTLIN-ALL-GENS] - fix escaping of values across all templates#23633
Open
Picazsoo wants to merge 5 commits intoOpenAPITools:masterfrom
Open
[KOTLIN-ALL-GENS] - fix escaping of values across all templates#23633Picazsoo wants to merge 5 commits intoOpenAPITools:masterfrom
Picazsoo wants to merge 5 commits intoOpenAPITools:masterfrom
Conversation
# Conflicts: # modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java
Contributor
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 @@ | |||
| /** | |||
Contributor
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, aligns parameter tables in docs, adds worst‑case spec, regenerates samples, and adds tests (fixes #20502).
Bug Fixes
lambda.escapeInNormalString,lambda.escapeDollarInMultiline, andlambda.escapeMarkdown.unescapedDefaultValuefields andlambda.escapeInNormalString; respects enums and multiline strings.CodegenOperation.unescapedSummary,CodegenResponse.unescapedMessage,CodegenParameter.unescapedDefaultValue,CodegenProperty.unescapedDefaultValue.kotlin-jvm-retrofit2, validate/sanitize@Pathnames and emitvendorExtensions.x-retrofit-path-nameto avoid invalid Retrofit placeholders.kotlin-clientand server templates (OkHttp, Retrofit2, Ktor, WebClient/RestClient, Spring, Javalin, JAX‑RS, Vert.x, Misk, WireMock), including@JsonPropertynames and annotation strings; fix API docs to use markdown‑safe texts and consistent parameter tables.issue20502-kotlin-string-escaping.yaml), newecho_apisamples forkotlin-jvm-okhttpandkotlin-jvm-spring-3-restclient, and tests covering$, backslashes, quotes, and comment markers. 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 67ee557. Summary will update on new commits. Review in cubic