Skip to content

Commit ab136df

Browse files
rvlasveldclaude
andauthored
[kotlin] do not HTML-escape property names in generated KDoc @PARAM (#25028)
Kotlin wraps a property name that is not a valid identifier in back-ticks, for example `2ndField` for a schema property named "2nd_field". The model templates rendered that name with a double-brace Mustache tag, which HTML escapes it, so the generated KDoc read: @PARAM &#x60;2ndField&#x60; An optional property ... Switch the two affected templates to a triple-brace tag, matching what kotlin-client, kotlin-server, ktor2 and jaxrs-spec already do. No committed sample changes, because no existing kotlin-spring or kotlin-vertx sample has a property name that needs back-ticks. The new test uses param-json-property.yaml, which does. Claude-Session: https://claude.ai/code/session_01VBn7VWUxZL6mTUbg21xNjm Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 11221eb commit ab136df

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* {{{description}}}
33
{{#requiredVars}}
4-
* @param {{name}} {{{description}}}
4+
* @param {{{name}}} {{{description}}}
55
{{/requiredVars}}
66
{{#optionalVars}}
7-
* @param {{name}} {{{description}}}
7+
* @param {{{name}}} {{{description}}}
88
{{/optionalVars}}
99
*/{{#discriminator}}
1010
{{>typeInfoAnnotation}}{{/discriminator}}

‎modules/openapi-generator/src/main/resources/kotlin-vertx-server/data_class.mustache‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
99
/**
1010
* {{{description}}}
1111
{{#vars}}
12-
* @param {{name}} {{{description}}}
12+
* @param {{{name}}} {{{description}}}
1313
{{/vars}}
1414
*/
1515
{{#parcelizeModels}}

‎modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7797,6 +7797,20 @@ public void paramJsonPropertyAnnotationWithDigitStartingPropertyName() throws IO
77977797
);
77987798
}
77997799

7800+
@Test(description = "KDoc @param must name the property literally, without HTML-escaping its back-ticks")
7801+
public void kdocParamNameIsNotHtmlEscaped() throws IOException {
7802+
Map<String, File> files = generateFromContract(
7803+
"src/test/resources/3_0/kotlin/param-json-property.yaml"
7804+
);
7805+
7806+
File itemFile = files.get("Item.kt");
7807+
assertThat(itemFile).isNotNull();
7808+
// "2nd_field" is not a valid Kotlin identifier, so the property is declared as `2ndField`.
7809+
// The KDoc must carry those back-ticks as written rather than as HTML entities.
7810+
assertFileNotContains(itemFile.toPath(), "&#x60;");
7811+
assertFileContains(itemFile.toPath(), "@param `2ndField` ");
7812+
}
7813+
78007814

78017815
/**
78027816
* Regression test for https://github.com/OpenAPITools/openapi-generator/issues/24139

0 commit comments

Comments
 (0)