|
1 | 1 | package org.openapitools.codegen.kotlin; |
2 | 2 |
|
| 3 | +import io.swagger.v3.oas.models.Operation; |
3 | 4 | import java.io.File; |
4 | 5 | import java.io.IOException; |
5 | 6 | import java.nio.file.Files; |
6 | 7 | import java.nio.file.Path; |
7 | 8 | import java.nio.file.Paths; |
8 | 9 | import java.util.HashMap; |
| 10 | +import java.util.List; |
9 | 11 | import java.util.Map; |
| 12 | +import org.openapitools.codegen.CodegenOperation; |
10 | 13 | import org.antlr.v4.runtime.CharStreams; |
11 | 14 | import org.antlr.v4.runtime.CommonTokenStream; |
12 | 15 | import org.antlr.v4.runtime.tree.ParseTree; |
@@ -515,33 +518,7 @@ public void fixJacksonJsonTypeInfoInheritance_canBeDisabled() throws IOException |
515 | 518 | ); |
516 | 519 | } |
517 | 520 |
|
518 | | - @Test |
519 | | - public void useTags_commonPathIsComputedForJaxrsSpecLibrary() throws IOException { |
520 | | - File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
521 | | - output.deleteOnExit(); |
522 | | - |
523 | | - KotlinServerCodegen codegen = new KotlinServerCodegen(); |
524 | | - codegen.setOutputDir(output.getAbsolutePath()); |
525 | | - codegen.additionalProperties().put(LIBRARY, JAXRS_SPEC); |
526 | | - codegen.additionalProperties().put(USE_TAGS, true); |
527 | | - |
528 | | - new DefaultGenerator().opts(new ClientOptInput() |
529 | | - .openAPI(TestUtils.parseSpec("src/test/resources/2_0/petstore.yaml")) |
530 | | - .config(codegen)) |
531 | | - .generate(); |
532 | | - |
533 | | - String outputPath = output.getAbsolutePath() + "/src/main/kotlin/org/openapitools/server"; |
534 | | - Path petApi = Paths.get(outputPath + "/apis/PetApi.kt"); |
535 | | - |
536 | | - assertFileContains( |
537 | | - petApi, |
538 | | - "@Path(\"/pet\")" |
539 | | - ); |
540 | | - assertFileNotContains( |
541 | | - petApi, |
542 | | - "@Path(\"/\")" |
543 | | - ); |
544 | | - } |
| 521 | + // ==================== useTags for JAXRS-SPEC ==================== |
545 | 522 |
|
546 | 523 | @Test |
547 | 524 | public void useTags_false_classNameFromTagsAndRootPathForJaxrsSpecLibrary() throws IOException { |
@@ -597,4 +574,57 @@ public void useTags_notSpecified_behavesLikeUseTagsTrueForJaxrsSpecLibrary() thr |
597 | 574 | assertFileNotContains(petApi, "@Path(\"/\")"); |
598 | 575 | assertFileNotContains(petApi, "@Path(\"/store\")"); |
599 | 576 | } |
| 577 | + |
| 578 | + // ==================== useTags for all libraries ==================== |
| 579 | + |
| 580 | + @Test |
| 581 | + public void useTags_false_groupsByFirstPathSegment() { |
| 582 | + KotlinServerCodegen codegen = new KotlinServerCodegen(); |
| 583 | + codegen.additionalProperties().put(LIBRARY, JAVALIN6); |
| 584 | + codegen.additionalProperties().put(USE_TAGS, false); |
| 585 | + codegen.processOpts(); |
| 586 | + |
| 587 | + CodegenOperation co = new CodegenOperation(); |
| 588 | + co.operationId = "findByStatus"; |
| 589 | + Map<String, List<CodegenOperation>> groups = new HashMap<>(); |
| 590 | + |
| 591 | + codegen.addOperationToGroup("Pet", "/pet/findByStatus", new Operation(), co, groups); |
| 592 | + |
| 593 | + Assert.assertTrue(groups.containsKey("pet")); |
| 594 | + Assert.assertEquals(co.baseName, "pet"); |
| 595 | + } |
| 596 | + |
| 597 | + @Test |
| 598 | + public void useTags_false_rootPath_groupsAsDefault() { |
| 599 | + KotlinServerCodegen codegen = new KotlinServerCodegen(); |
| 600 | + codegen.additionalProperties().put(LIBRARY, JAVALIN6); |
| 601 | + codegen.additionalProperties().put(USE_TAGS, false); |
| 602 | + codegen.processOpts(); |
| 603 | + |
| 604 | + CodegenOperation co = new CodegenOperation(); |
| 605 | + co.operationId = "getRoot"; |
| 606 | + Map<String, List<CodegenOperation>> groups = new HashMap<>(); |
| 607 | + |
| 608 | + codegen.addOperationToGroup("Root", "/", new Operation(), co, groups); |
| 609 | + |
| 610 | + Assert.assertTrue(groups.containsKey("default")); |
| 611 | + Assert.assertEquals(co.baseName, "default"); |
| 612 | + } |
| 613 | + |
| 614 | + @Test |
| 615 | + public void useTags_false_pathParamOnly_groupsAsDefault() { |
| 616 | + KotlinServerCodegen codegen = new KotlinServerCodegen(); |
| 617 | + codegen.additionalProperties().put(LIBRARY, JAVALIN6); |
| 618 | + codegen.additionalProperties().put(USE_TAGS, false); |
| 619 | + codegen.processOpts(); |
| 620 | + |
| 621 | + CodegenOperation co = new CodegenOperation(); |
| 622 | + co.operationId = "getById"; |
| 623 | + Map<String, List<CodegenOperation>> groups = new HashMap<>(); |
| 624 | + |
| 625 | + codegen.addOperationToGroup("Resource", "/{uuid}", new Operation(), co, groups); |
| 626 | + |
| 627 | + Assert.assertTrue(groups.containsKey("default")); |
| 628 | + Assert.assertEquals(co.baseName, "default"); |
| 629 | + } |
600 | 630 | } |
0 commit comments