Skip to content

Commit a86a9f1

Browse files
committed
add unit test
1 parent c9ce225 commit a86a9f1

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public static void assertFileNotContains(Path path, String... lines) {
208208
String file = linearize(generatedFile);
209209
assertNotNull(file);
210210
for (String line : lines)
211-
assertFalse(file.contains(linearize(line)));
211+
assertFalse(file.contains(linearize(line)), "File '" + path + "' contains line [" + line + "] when it should not");
212212
}
213213

214214
public static void assertFileNotExists(Path path) {

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,6 +2585,60 @@ public void testValidationsInQueryParams_issue21238_Api_Delegate() {
25852585
));
25862586
}
25872587

2588+
2589+
@Test
2590+
public void testDollarsAndQuotesSwagger1() {
2591+
Path apiSources = generateApiSources(
2592+
"src/test/resources/3_0/kotlin/petstore-with-tags.yaml",
2593+
Map.of(
2594+
KotlinSpringServerCodegen.DOCUMENTATION_PROVIDER, "springfox",
2595+
KotlinSpringServerCodegen.ANNOTATION_LIBRARY, "swagger1",
2596+
KotlinSpringServerCodegen.DELEGATE_PATTERN, true
2597+
),
2598+
Map.of(
2599+
CodegenConstants.MODELS, "true",
2600+
CodegenConstants.MODEL_TESTS, "false",
2601+
CodegenConstants.MODEL_DOCS, "false",
2602+
CodegenConstants.APIS, "true",
2603+
CodegenConstants.SUPPORTING_FILES, "false"
2604+
)
2605+
);
2606+
assertGeneratedFilesContain(Map.of(
2607+
apiSources.resolve("src/main/kotlin/org/openapitools/api/itemsApi.kt"),
2608+
List.of("value = \"SQ = \\\"; SBS = \\\\; DBS = \\\\\\\\; SD = \\$some\"",
2609+
"@PathVariable(\"item\\$Id\")",
2610+
"@PathVariable(\"item\\$SubId\")",
2611+
"@RequestParam(value = \"filter\\$Type\"",
2612+
"@RequestParam(value = \"filter\\$SubType\"",
2613+
"@CookieValue(name = \"session\\$Token\"",
2614+
"@CookieValue(name = \"session\\$TokenTwo\"",
2615+
"@RequestParam(value = \"form\\$Name\"",
2616+
"@RequestParam(value = \"form\\$Value\"",
2617+
"PATH_ITEMS_ITEM_ID_SOMETHING_ITEM_SUB_ID_GET: String = \"/items/{item\\$Id}/something/{item\\$SubId}\"",
2618+
"/* \"/items/{item$Id}/something/{item$SubId}\" */"
2619+
)
2620+
));
2621+
assertGeneratedFilesNotContain(Map.of(
2622+
apiSources.resolve("src/main/kotlin/org/openapitools/api/itemsApi.kt"),
2623+
List.of(
2624+
"SQ = \\\\\";",
2625+
"SBS = \\\\\\\\;",
2626+
"DBS = \\\\\\\\\\\\\\\\;",
2627+
"SD = \\\\$some",
2628+
"@PathVariable(\"item$Id\")",
2629+
"@PathVariable(\"item$SubId\")",
2630+
"@RequestParam(value = \"filter$Type\"",
2631+
"@RequestParam(value = \"filter$SubType\"",
2632+
"@CookieValue(name = \"session$Token\"",
2633+
"@CookieValue(name = \"session$TokenTwo\"",
2634+
"@RequestParam(value = \"form$Name\"",
2635+
"@RequestParam(value = \"form$Value\"",
2636+
"PATH_ITEMS_ITEM_ID_SOMETHING_ITEM_SUB_ID_GET: String = \"/items/{item$Id}/something/{item$SubId}\"",
2637+
"/* \"/items/{item\\$Id}/something/{item\\$SubId}\" */"
2638+
)
2639+
));
2640+
}
2641+
25882642
private Path generateApiSources(
25892643
String specFilePath,
25902644
Map<String, Object> additionalProperties,

0 commit comments

Comments
 (0)