Skip to content

Commit b4d799f

Browse files
committed
add tests for issue #21238
1 parent a87f559 commit b4d799f

2 files changed

Lines changed: 116 additions & 0 deletions

File tree

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,4 +1137,59 @@ public void nonReactiveWithFlow() throws Exception {
11371137
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"),
11381138
"Flow<kotlin.String>");
11391139
}
1140+
1141+
@Test
1142+
public void testValidationsInQueryParams_issue21238_Controller() throws IOException {
1143+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
1144+
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
1145+
codegen.setOutputDir(output.getAbsolutePath());
1146+
1147+
List<File> files = new DefaultGenerator()
1148+
.opts(
1149+
new ClientOptInput()
1150+
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue21238_queryParam_validation.yaml"))
1151+
.config(codegen)
1152+
)
1153+
.generate();
1154+
1155+
Assertions.assertThat(files).contains(
1156+
new File(output, "src/main/kotlin/org/openapitools/api/PetApiController.kt"),
1157+
new File(output, "src/main/kotlin/org/openapitools/api/UserApiController.kt")
1158+
);
1159+
1160+
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/PetApiController.kt"),
1161+
"@NotNull", "@Valid");
1162+
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/UserApiController.kt"),
1163+
"@NotNull", "@Valid",
1164+
"@Pattern(regexp=\"^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$\")",
1165+
"@Parameter(description = \"The user name for login\", required = true)",
1166+
"@Parameter(description = \"The password for login in clear text\", required = true)");
1167+
}
1168+
1169+
@Test
1170+
public void testValidationsInQueryParams_issue21238_Api_Delegate() throws IOException {
1171+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
1172+
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
1173+
codegen.setOutputDir(output.getAbsolutePath());
1174+
codegen.additionalProperties().put(KotlinSpringServerCodegen.DELEGATE_PATTERN, true);
1175+
1176+
List<File> files = new DefaultGenerator()
1177+
.opts(
1178+
new ClientOptInput()
1179+
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue21238_queryParam_validation.yaml"))
1180+
.config(codegen)
1181+
)
1182+
.generate();
1183+
1184+
Assertions.assertThat(files).contains(
1185+
new File(output, "src/main/kotlin/org/openapitools/api/PetApi.kt"),
1186+
new File(output, "src/main/kotlin/org/openapitools/api/UserApi.kt")
1187+
);
1188+
1189+
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/PetApi.kt"),
1190+
"@NotNull", "@Valid");
1191+
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/UserApi.kt"),
1192+
"@NotNull", "@Valid", "@Pattern(regexp=\"^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$\")");
1193+
}
1194+
11401195
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
openapi: 3.0.0
2+
info:
3+
description: "Example to test fix for issue 21238, queryParam validation"
4+
license:
5+
name: Apache-2.0
6+
url: https://www.apache.org/licenses/LICENSE-2.0.html
7+
title: OpenAPI Query Param VAlidation
8+
version: 1.0.0
9+
paths:
10+
/pet/findByStatus:
11+
get:
12+
description: Multiple status values can be provided with comma separated strings
13+
operationId: findPetsByStatus
14+
parameters:
15+
- deprecated: true
16+
description: Status values that need to be considered for filter
17+
explode: false
18+
in: query
19+
name: status
20+
required: true
21+
schema:
22+
items:
23+
default: available
24+
enum:
25+
- available
26+
- pending
27+
- sold
28+
type: string
29+
type: array
30+
style: form
31+
responses:
32+
"200":
33+
summary: Finds Pets by status
34+
tags:
35+
- pet
36+
/user/login:
37+
get:
38+
operationId: loginUser
39+
parameters:
40+
- description: The user name for login
41+
explode: true
42+
in: query
43+
name: username
44+
required: true
45+
schema:
46+
pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"
47+
type: string
48+
style: form
49+
- description: The password for login in clear text
50+
explode: true
51+
in: query
52+
name: password
53+
required: true
54+
schema:
55+
type: string
56+
style: form
57+
responses:
58+
"200":
59+
summary: Logs user into the system
60+
tags:
61+
- user

0 commit comments

Comments
 (0)