|
25 | 25 | import io.swagger.v3.parser.core.models.ParseOptions;
|
26 | 26 | import io.swagger.v3.parser.util.SchemaTypeUtil;
|
27 | 27 | import org.openapitools.codegen.*;
|
| 28 | +import org.openapitools.codegen.config.CodegenConfigurator; |
28 | 29 | import org.openapitools.codegen.languages.PythonClientCodegen;
|
29 | 30 | import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
30 | 31 | import org.testng.Assert;
|
@@ -611,4 +612,77 @@ public void testInitFileImportsExports() throws IOException {
|
611 | 612 | assertFileContains(initFilePath, "from openapi_client.models.tag import Tag as Tag");
|
612 | 613 | assertFileContains(initFilePath, "from openapi_client.models.user import User as User");
|
613 | 614 | }
|
| 615 | + |
| 616 | + @Test(description = "Verify default license format uses object notation when poetry1 is false") |
| 617 | + public void testLicenseFormatInPyprojectToml() throws IOException { |
| 618 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 619 | + output.deleteOnExit(); |
| 620 | + |
| 621 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 622 | + .setGeneratorName("python") |
| 623 | + .setInputSpec("src/test/resources/bugs/issue_21619.yaml") |
| 624 | + .setOutputDir(output.getAbsolutePath()) |
| 625 | + .addAdditionalProperty("licenseInfo", "MIT"); |
| 626 | + |
| 627 | + DefaultGenerator generator = new DefaultGenerator(); |
| 628 | + List<File> files = generator.opts(configurator.toClientOptInput()).generate(); |
| 629 | + files.forEach(File::deleteOnExit); |
| 630 | + |
| 631 | + TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "pyproject.toml")); |
| 632 | + // When poetry1=false (default), license should use object notation: { text = "MIT" } |
| 633 | + TestUtils.assertFileContains(Paths.get(output.getAbsolutePath(), "pyproject.toml"), |
| 634 | + "license = { text = \"MIT\" }"); |
| 635 | + } |
| 636 | + |
| 637 | + @Test(description = "Verify poetry1 mode uses string notation for license") |
| 638 | + public void testPoetry1LicenseFormat() throws IOException { |
| 639 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 640 | + output.deleteOnExit(); |
| 641 | + |
| 642 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 643 | + .setGeneratorName("python") |
| 644 | + .setInputSpec("src/test/resources/bugs/issue_21619.yaml") |
| 645 | + .setOutputDir(output.getAbsolutePath()) |
| 646 | + .addAdditionalProperty("licenseInfo", "Apache-2.0") |
| 647 | + .addAdditionalProperty("poetry1", true); // Enable legacy poetry1 mode |
| 648 | + |
| 649 | + DefaultGenerator generator = new DefaultGenerator(); |
| 650 | + List<File> files = generator.opts(configurator.toClientOptInput()).generate(); |
| 651 | + files.forEach(File::deleteOnExit); |
| 652 | + |
| 653 | + Path pyprojectPath = Paths.get(output.getAbsolutePath(), "pyproject.toml"); |
| 654 | + TestUtils.assertFileExists(pyprojectPath); |
| 655 | + |
| 656 | + // In poetry1 mode, license should use simple string format: "Apache-2.0" |
| 657 | + TestUtils.assertFileContains(pyprojectPath, "license = \"Apache-2.0\""); |
| 658 | + |
| 659 | + // Verify it does NOT use the new object format |
| 660 | + TestUtils.assertFileNotContains(pyprojectPath, "license = { text = \"Apache-2.0\" }"); |
| 661 | + } |
| 662 | + |
| 663 | + @Test(description = "Verify non-poetry1 mode uses object notation for license") |
| 664 | + public void testNonPoetry1LicenseFormat() throws IOException { |
| 665 | + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); |
| 666 | + output.deleteOnExit(); |
| 667 | + |
| 668 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 669 | + .setGeneratorName("python") |
| 670 | + .setInputSpec("src/test/resources/bugs/issue_21619.yaml") |
| 671 | + .setOutputDir(output.getAbsolutePath()) |
| 672 | + .addAdditionalProperty("licenseInfo", "BSD-3-Clause") |
| 673 | + .addAdditionalProperty("poetry1", false); // Explicitly disable poetry1 mode |
| 674 | + |
| 675 | + DefaultGenerator generator = new DefaultGenerator(); |
| 676 | + List<File> files = generator.opts(configurator.toClientOptInput()).generate(); |
| 677 | + files.forEach(File::deleteOnExit); |
| 678 | + |
| 679 | + Path pyprojectPath = Paths.get(output.getAbsolutePath(), "pyproject.toml"); |
| 680 | + TestUtils.assertFileExists(pyprojectPath); |
| 681 | + |
| 682 | + // In non-poetry1 mode, license should use object format: { text = "BSD-3-Clause" } |
| 683 | + TestUtils.assertFileContains(pyprojectPath, "license = { text = \"BSD-3-Clause\" }"); |
| 684 | + |
| 685 | + // Verify it does NOT use the legacy string format |
| 686 | + TestUtils.assertFileNotContains(pyprojectPath, "license = \"BSD-3-Clause\""); |
| 687 | + } |
614 | 688 | }
|
0 commit comments