Skip to content

Commit b8bc349

Browse files
committed
add missing unit test
1 parent 7407e6e commit b8bc349

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenApiTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,29 @@ public void testJvmOkHttp4ApiClientUsesExplicitDateTypeArgumentsForQuerySerializ
171171
assertFileNotContains(Paths.get(apiClientPath), "is OffsetDateTime -> parseDateToQueryString(value)");
172172
}
173173

174+
@Test
175+
public void testDollarInPathParamSanitizedForRetrofit2_20502() throws IOException {
176+
OpenAPI openAPI = readOpenAPI("src/test/resources/3_0/kotlin/echo_api.yaml");
177+
178+
KotlinClientCodegen codegen = createCodegen(ClientLibrary.JVM_RETROFIT2);
179+
codegen.additionalProperties().put(KotlinClientCodegen.USE_COROUTINES, "true");
180+
codegen.additionalProperties().put(KotlinClientCodegen.USE_RESPONSE_AS_RETURN_TYPE, "true");
181+
182+
ClientOptInput input = createClientOptInput(openAPI, codegen);
183+
DefaultGenerator generator = new DefaultGenerator();
184+
enableOnlyApiGeneration(generator);
185+
186+
List<File> files = generator.opts(input).generate();
187+
File echoApi = files.stream().filter(file -> file.getName().equals("EchoApi.kt")).findAny().orElseThrow();
188+
189+
// Retrofit @Path name must not contain '$' — must use the sanitized paramName
190+
assertFileContains(echoApi.toPath(), "@Path(\"dollarParamName\")");
191+
assertFileContains(echoApi.toPath(), "echo/string-escaping/{dollarParamName}");
192+
// Raw '$paramName' must never appear in the @Path annotation value
193+
assertFileNotContains(echoApi.toPath(), "@Path(\"$paramName\")");
194+
assertFileNotContains(echoApi.toPath(), "@Path(\"\\$paramName\")");
195+
}
196+
174197
@Test(dataProvider = "librariesWithDateQueryHelper")
175198
public void testGeneratedApisUseExplicitDateTypeArgumentsForQuerySerialization(ClientLibrary library) throws IOException {
176199
OpenAPI openAPI = readOpenAPI("3_0/kotlin/echo_api.yaml");

0 commit comments

Comments
 (0)