|
1 | 1 | package org.openapitools.codegen.kotlin.spring;
|
2 | 2 |
|
3 | 3 | import com.google.common.collect.testing.Helpers;
|
| 4 | +import io.swagger.parser.OpenAPIParser; |
4 | 5 | import io.swagger.v3.oas.models.OpenAPI;
|
5 | 6 | import io.swagger.v3.oas.models.info.Info;
|
6 | 7 | import io.swagger.v3.oas.models.servers.Server;
|
| 8 | +import io.swagger.v3.parser.core.models.ParseOptions; |
7 | 9 | import org.apache.commons.io.FileUtils;
|
8 | 10 | import org.openapitools.codegen.ClientOptInput;
|
9 | 11 | import org.openapitools.codegen.CodegenConstants;
|
10 | 12 | import org.openapitools.codegen.DefaultGenerator;
|
11 | 13 | import org.openapitools.codegen.TestUtils;
|
12 | 14 | import org.openapitools.codegen.kotlin.KotlinTestUtils;
|
13 | 15 | import org.openapitools.codegen.languages.KotlinSpringServerCodegen;
|
| 16 | +import org.openapitools.codegen.languages.features.CXFServerFeatures; |
14 | 17 | import org.testng.Assert;
|
15 | 18 | import org.testng.annotations.Test;
|
16 | 19 |
|
17 | 20 | import java.io.File;
|
| 21 | +import java.io.IOException; |
18 | 22 | import java.nio.file.Files;
|
19 | 23 | import java.nio.file.Paths;
|
20 | 24 | import java.util.Collections;
|
@@ -253,4 +257,107 @@ public void delegateReactiveWithTags() throws Exception {
|
253 | 257 | assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV2ApiDelegate.kt"),
|
254 | 258 | "suspend fun", "ApiUtil");
|
255 | 259 | }
|
| 260 | + |
| 261 | + @Test |
| 262 | + public void doNotGenerateRequestParamForObjectQueryParam() throws IOException { |
| 263 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 264 | + output.deleteOnExit(); |
| 265 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 266 | + |
| 267 | + OpenAPI openAPI = new OpenAPIParser() |
| 268 | + .readLocation("src/test/resources/3_0/objectQueryParam.yaml", null, new ParseOptions()).getOpenAPI(); |
| 269 | + |
| 270 | + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 271 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 272 | + codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true"); |
| 273 | + |
| 274 | + ClientOptInput input = new ClientOptInput(); |
| 275 | + input.openAPI(openAPI); |
| 276 | + input.config(codegen); |
| 277 | + |
| 278 | + DefaultGenerator generator = new DefaultGenerator(); |
| 279 | + |
| 280 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "false"); |
| 281 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); |
| 282 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); |
| 283 | + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true"); |
| 284 | + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false"); |
| 285 | + |
| 286 | + generator.opts(input).generate(); |
| 287 | + |
| 288 | + assertFileNotContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PonyApi.kt"), "@RequestParam"); |
| 289 | + } |
| 290 | + |
| 291 | + @Test |
| 292 | + public void doGenerateRequestParamForSimpleParam() throws IOException { |
| 293 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 294 | + output.deleteOnExit(); |
| 295 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 296 | + |
| 297 | + OpenAPI openAPI = new OpenAPIParser() |
| 298 | + .readLocation("src/test/resources/3_0/issue_3248.yaml", null, new ParseOptions()).getOpenAPI(); |
| 299 | + |
| 300 | + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 301 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 302 | + codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true"); |
| 303 | + |
| 304 | + ClientOptInput input = new ClientOptInput(); |
| 305 | + input.openAPI(openAPI); |
| 306 | + input.config(codegen); |
| 307 | + |
| 308 | + DefaultGenerator generator = new DefaultGenerator(); |
| 309 | + |
| 310 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "false"); |
| 311 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); |
| 312 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); |
| 313 | + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true"); |
| 314 | + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false"); |
| 315 | + |
| 316 | + generator.opts(input).generate(); |
| 317 | + |
| 318 | + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/MonkeysApi.kt"), "@RequestParam"); |
| 319 | + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/ElephantsApi.kt"), "@RequestParam"); |
| 320 | + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/ZebrasApi.kt"), "@RequestParam"); |
| 321 | + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/BearsApi.kt"), "@RequestParam"); |
| 322 | + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/CamelsApi.kt"), "@RequestParam"); |
| 323 | + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PandasApi.kt"), "@RequestParam"); |
| 324 | + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/CrocodilesApi.kt"), "@RequestParam"); |
| 325 | + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PolarBearsApi.kt"), "@RequestParam"); |
| 326 | + } |
| 327 | + |
| 328 | + @Test |
| 329 | + public void generateFormatForDateAndDateTimeQueryParam() throws IOException { |
| 330 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 331 | + output.deleteOnExit(); |
| 332 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 333 | + |
| 334 | + OpenAPI openAPI = new OpenAPIParser() |
| 335 | + .readLocation("src/test/resources/3_0/issue_2053.yaml", null, new ParseOptions()).getOpenAPI(); |
| 336 | + |
| 337 | + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); |
| 338 | + codegen.setOutputDir(output.getAbsolutePath()); |
| 339 | + codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true"); |
| 340 | + |
| 341 | + ClientOptInput input = new ClientOptInput(); |
| 342 | + input.openAPI(openAPI); |
| 343 | + input.config(codegen); |
| 344 | + |
| 345 | + DefaultGenerator generator = new DefaultGenerator(); |
| 346 | + |
| 347 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "false"); |
| 348 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); |
| 349 | + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); |
| 350 | + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true"); |
| 351 | + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false"); |
| 352 | + generator.opts(input).generate(); |
| 353 | + |
| 354 | + assertFileContains( |
| 355 | + Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/ElephantsApi.kt"), |
| 356 | + "@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)" |
| 357 | + ); |
| 358 | + assertFileContains( |
| 359 | + Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/ZebrasApi.kt"), |
| 360 | + "@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)" |
| 361 | + ); |
| 362 | + } |
256 | 363 | }
|
0 commit comments