mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
add tests for issue #21238
This commit is contained in:
parent
a87f55900f
commit
b4d799f010
@ -1137,4 +1137,59 @@ public class KotlinSpringServerCodegenTest {
|
||||
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"),
|
||||
"Flow<kotlin.String>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationsInQueryParams_issue21238_Controller() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||
codegen.setOutputDir(output.getAbsolutePath());
|
||||
|
||||
List<File> files = new DefaultGenerator()
|
||||
.opts(
|
||||
new ClientOptInput()
|
||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue21238_queryParam_validation.yaml"))
|
||||
.config(codegen)
|
||||
)
|
||||
.generate();
|
||||
|
||||
Assertions.assertThat(files).contains(
|
||||
new File(output, "src/main/kotlin/org/openapitools/api/PetApiController.kt"),
|
||||
new File(output, "src/main/kotlin/org/openapitools/api/UserApiController.kt")
|
||||
);
|
||||
|
||||
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/PetApiController.kt"),
|
||||
"@NotNull", "@Valid");
|
||||
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/UserApiController.kt"),
|
||||
"@NotNull", "@Valid",
|
||||
"@Pattern(regexp=\"^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$\")",
|
||||
"@Parameter(description = \"The user name for login\", required = true)",
|
||||
"@Parameter(description = \"The password for login in clear text\", required = true)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationsInQueryParams_issue21238_Api_Delegate() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||
codegen.setOutputDir(output.getAbsolutePath());
|
||||
codegen.additionalProperties().put(KotlinSpringServerCodegen.DELEGATE_PATTERN, true);
|
||||
|
||||
List<File> files = new DefaultGenerator()
|
||||
.opts(
|
||||
new ClientOptInput()
|
||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue21238_queryParam_validation.yaml"))
|
||||
.config(codegen)
|
||||
)
|
||||
.generate();
|
||||
|
||||
Assertions.assertThat(files).contains(
|
||||
new File(output, "src/main/kotlin/org/openapitools/api/PetApi.kt"),
|
||||
new File(output, "src/main/kotlin/org/openapitools/api/UserApi.kt")
|
||||
);
|
||||
|
||||
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/PetApi.kt"),
|
||||
"@NotNull", "@Valid");
|
||||
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/UserApi.kt"),
|
||||
"@NotNull", "@Valid", "@Pattern(regexp=\"^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$\")");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
description: "Example to test fix for issue 21238, queryParam validation"
|
||||
license:
|
||||
name: Apache-2.0
|
||||
url: https://www.apache.org/licenses/LICENSE-2.0.html
|
||||
title: OpenAPI Query Param VAlidation
|
||||
version: 1.0.0
|
||||
paths:
|
||||
/pet/findByStatus:
|
||||
get:
|
||||
description: Multiple status values can be provided with comma separated strings
|
||||
operationId: findPetsByStatus
|
||||
parameters:
|
||||
- deprecated: true
|
||||
description: Status values that need to be considered for filter
|
||||
explode: false
|
||||
in: query
|
||||
name: status
|
||||
required: true
|
||||
schema:
|
||||
items:
|
||||
default: available
|
||||
enum:
|
||||
- available
|
||||
- pending
|
||||
- sold
|
||||
type: string
|
||||
type: array
|
||||
style: form
|
||||
responses:
|
||||
"200":
|
||||
summary: Finds Pets by status
|
||||
tags:
|
||||
- pet
|
||||
/user/login:
|
||||
get:
|
||||
operationId: loginUser
|
||||
parameters:
|
||||
- description: The user name for login
|
||||
explode: true
|
||||
in: query
|
||||
name: username
|
||||
required: true
|
||||
schema:
|
||||
pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"
|
||||
type: string
|
||||
style: form
|
||||
- description: The password for login in clear text
|
||||
explode: true
|
||||
in: query
|
||||
name: password
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
style: form
|
||||
responses:
|
||||
"200":
|
||||
summary: Logs user into the system
|
||||
tags:
|
||||
- user
|
Loading…
x
Reference in New Issue
Block a user