From 89d7af1b3ceb6d26e7daf6b68ad7b1c3236adfb5 Mon Sep 17 00:00:00 2001 From: keepConcentration Date: Sat, 9 Aug 2025 16:51:48 +0900 Subject: [PATCH 1/5] Add support for both string and object license formats in `pyproject.toml` for Python and Python-Pydantic generators. (#21619) --- .../python-pydantic-v1/pyproject.mustache | 2 +- .../main/resources/python/pyproject.mustache | 5 ++ .../python/PythonClientCodegenTest.java | 74 +++++++++++++++++++ .../PythonPydanticV1ClientCodegenTest.java | 42 +++++++++++ .../src/test/resources/bugs/issue_21619.yaml | 31 ++++++++ 5 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 modules/openapi-generator/src/test/resources/bugs/issue_21619.yaml diff --git a/modules/openapi-generator/src/main/resources/python-pydantic-v1/pyproject.mustache b/modules/openapi-generator/src/main/resources/python-pydantic-v1/pyproject.mustache index 8892d1566f32..d1c934ee4ec8 100644 --- a/modules/openapi-generator/src/main/resources/python-pydantic-v1/pyproject.mustache +++ b/modules/openapi-generator/src/main/resources/python-pydantic-v1/pyproject.mustache @@ -3,7 +3,7 @@ name = "{{{packageName}}}" version = "{{{packageVersion}}}" description = "{{{appName}}}" authors = ["{{infoName}}{{^infoName}}OpenAPI Generator Community{{/infoName}} <{{infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}>"] -license = "{{{licenseInfo}}}{{^licenseInfo}}Unlicense{{/licenseInfo}}" +license = { text = "{{{licenseInfo}}}{{^licenseInfo}}Unlicense{{/licenseInfo}}" } readme = "README.md" repository = "https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}" keywords = ["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"] diff --git a/modules/openapi-generator/src/main/resources/python/pyproject.mustache b/modules/openapi-generator/src/main/resources/python/pyproject.mustache index d5b2826be9a2..5f7f15811368 100644 --- a/modules/openapi-generator/src/main/resources/python/pyproject.mustache +++ b/modules/openapi-generator/src/main/resources/python/pyproject.mustache @@ -16,7 +16,12 @@ authors = [ ] {{/poetry1}} {{#licenseInfo}} +{{#poetry1}} license = "{{{licenseInfo}}}" +{{/poetry1}} +{{^poetry1}} +license = { text = "{{{licenseInfo}}}" } +{{/poetry1}} {{/licenseInfo}} readme = "README.md" {{#poetry1}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java index 0735ccc4f6f7..a18f2f40d11b 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java @@ -25,6 +25,7 @@ import io.swagger.v3.parser.core.models.ParseOptions; import io.swagger.v3.parser.util.SchemaTypeUtil; import org.openapitools.codegen.*; +import org.openapitools.codegen.config.CodegenConfigurator; import org.openapitools.codegen.languages.PythonClientCodegen; import org.openapitools.codegen.languages.features.CXFServerFeatures; import org.testng.Assert; @@ -611,4 +612,77 @@ public void testInitFileImportsExports() throws IOException { assertFileContains(initFilePath, "from openapi_client.models.tag import Tag as Tag"); assertFileContains(initFilePath, "from openapi_client.models.user import User as User"); } + + @Test(description = "Verify default license format uses object notation when poetry1 is false") + public void testLicenseFormatInPyprojectToml() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("python") + .setInputSpec("src/test/resources/bugs/issue_21619.yaml") + .setOutputDir(output.getAbsolutePath()) + .addAdditionalProperty("licenseInfo", "MIT"); + + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(configurator.toClientOptInput()).generate(); + files.forEach(File::deleteOnExit); + + TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "pyproject.toml")); + // When poetry1=false (default), license should use object notation: { text = "MIT" } + TestUtils.assertFileContains(Paths.get(output.getAbsolutePath(), "pyproject.toml"), + "license = { text = \"MIT\" }"); + } + + @Test(description = "Verify poetry1 mode uses string notation for license") + public void testPoetry1LicenseFormat() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("python") + .setInputSpec("src/test/resources/bugs/issue_21619.yaml") + .setOutputDir(output.getAbsolutePath()) + .addAdditionalProperty("licenseInfo", "Apache-2.0") + .addAdditionalProperty("poetry1", true); // Enable legacy poetry1 mode + + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(configurator.toClientOptInput()).generate(); + files.forEach(File::deleteOnExit); + + Path pyprojectPath = Paths.get(output.getAbsolutePath(), "pyproject.toml"); + TestUtils.assertFileExists(pyprojectPath); + + // In poetry1 mode, license should use simple string format: "Apache-2.0" + TestUtils.assertFileContains(pyprojectPath, "license = \"Apache-2.0\""); + + // Verify it does NOT use the new object format + TestUtils.assertFileNotContains(pyprojectPath, "license = { text = \"Apache-2.0\" }"); + } + + @Test(description = "Verify non-poetry1 mode uses object notation for license") + public void testNonPoetry1LicenseFormat() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("python") + .setInputSpec("src/test/resources/bugs/issue_21619.yaml") + .setOutputDir(output.getAbsolutePath()) + .addAdditionalProperty("licenseInfo", "BSD-3-Clause") + .addAdditionalProperty("poetry1", false); // Explicitly disable poetry1 mode + + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(configurator.toClientOptInput()).generate(); + files.forEach(File::deleteOnExit); + + Path pyprojectPath = Paths.get(output.getAbsolutePath(), "pyproject.toml"); + TestUtils.assertFileExists(pyprojectPath); + + // In non-poetry1 mode, license should use object format: { text = "BSD-3-Clause" } + TestUtils.assertFileContains(pyprojectPath, "license = { text = \"BSD-3-Clause\" }"); + + // Verify it does NOT use the legacy string format + TestUtils.assertFileNotContains(pyprojectPath, "license = \"BSD-3-Clause\""); + } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonPydanticV1ClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonPydanticV1ClientCodegenTest.java index 1c2fd629ce3b..df0e185b87dc 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonPydanticV1ClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonPydanticV1ClientCodegenTest.java @@ -25,6 +25,7 @@ import io.swagger.v3.parser.core.models.ParseOptions; import io.swagger.v3.parser.util.SchemaTypeUtil; import org.openapitools.codegen.*; +import org.openapitools.codegen.config.CodegenConfigurator; import org.openapitools.codegen.languages.PythonPydanticV1ClientCodegen; import org.openapitools.codegen.languages.features.CXFServerFeatures; import org.testng.Assert; @@ -534,4 +535,45 @@ public void testInitFileImportsExports() throws Exception { assertFileContains(initFilePath, "from openapi_client.models.tag import Tag as Tag"); assertFileContains(initFilePath, "from openapi_client.models.user import User as User"); } + + @Test(description = "Verify pydantic-v1 always uses object notation for license") + public void testLicenseFormatInPyprojectToml() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("python-pydantic-v1") + .setInputSpec("src/test/resources/bugs/issue_21619.yaml") + .setOutputDir(output.getAbsolutePath()) + .addAdditionalProperty("licenseInfo", "MIT"); + + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(configurator.toClientOptInput()).generate(); + files.forEach(File::deleteOnExit); + + TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "pyproject.toml")); + // python-pydantic-v1 always uses object notation regardless of poetry1 + TestUtils.assertFileContains(Paths.get(output.getAbsolutePath(), "pyproject.toml"), + "license = { text = \"MIT\" }"); + } + + @Test(description = "Verify pydantic-v1 uses default license when licenseInfo not provided") + public void testDefaultLicenseInPyprojectToml() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("python-pydantic-v1") + .setInputSpec("src/test/resources/bugs/issue_21619.yaml") + .setOutputDir(output.getAbsolutePath()); + + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(configurator.toClientOptInput()).generate(); + files.forEach(File::deleteOnExit); + + TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "pyproject.toml")); + // Should use default "Unlicense" + TestUtils.assertFileContains(Paths.get(output.getAbsolutePath(), "pyproject.toml"), + "license = { text = \"Unlicense\" }"); + } } diff --git a/modules/openapi-generator/src/test/resources/bugs/issue_21619.yaml b/modules/openapi-generator/src/test/resources/bugs/issue_21619.yaml new file mode 100644 index 000000000000..a257599d4414 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/bugs/issue_21619.yaml @@ -0,0 +1,31 @@ +openapi: 3.0.0 +info: + title: License Format Test API + version: 1.0.0 + description: Simple API for testing pyproject.toml license format changes +paths: + /test: + get: + operationId: getTest + summary: Simple test endpoint + responses: + '200': + description: Success + content: + application/json: + schema: + type: object + properties: + message: + type: string + example: "Hello World" +components: + schemas: + TestModel: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string From dd6bde3af6c96beec9eddb0b721719706f927b77 Mon Sep 17 00:00:00 2001 From: keepConcentration Date: Sun, 10 Aug 2025 11:45:54 +0900 Subject: [PATCH 2/5] Generate the samples (#21698) --- .../pyproject.toml | 2 +- samples/client/echo_api/python-pydantic-v1/pyproject.toml | 2 +- samples/client/echo_api/python/pyproject.toml | 2 +- .../client/petstore/python-pydantic-v1-aiohttp/pyproject.toml | 2 +- .../openapi3/client/petstore/python-pydantic-v1/pyproject.toml | 2 +- samples/openapi3/client/petstore/python/pyproject.toml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml index 25952c26ec86..fcf9c73b1528 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml @@ -5,7 +5,7 @@ description = "Echo Server API" authors = [ {name = "OpenAPI Generator Community",email = "team@openapitools.org"}, ] -license = "Apache 2.0" +license = { text = "Apache 2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] requires-python = ">=3.9" diff --git a/samples/client/echo_api/python-pydantic-v1/pyproject.toml b/samples/client/echo_api/python-pydantic-v1/pyproject.toml index 192e7c548361..08cecd35678a 100644 --- a/samples/client/echo_api/python-pydantic-v1/pyproject.toml +++ b/samples/client/echo_api/python-pydantic-v1/pyproject.toml @@ -3,7 +3,7 @@ name = "openapi_client" version = "1.0.0" description = "Echo Server API" authors = ["OpenAPI Generator Community "] -license = "Apache 2.0" +license = { text = "Apache 2.0" } readme = "README.md" repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] diff --git a/samples/client/echo_api/python/pyproject.toml b/samples/client/echo_api/python/pyproject.toml index 25952c26ec86..fcf9c73b1528 100644 --- a/samples/client/echo_api/python/pyproject.toml +++ b/samples/client/echo_api/python/pyproject.toml @@ -5,7 +5,7 @@ description = "Echo Server API" authors = [ {name = "OpenAPI Generator Community",email = "team@openapitools.org"}, ] -license = "Apache 2.0" +license = { text = "Apache 2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] requires-python = ">=3.9" diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml index d65781e4a8a8..3afb571fa277 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml @@ -3,7 +3,7 @@ name = "petstore_api" version = "1.0.0" description = "OpenAPI Petstore" authors = ["OpenAPI Generator Community "] -license = "Apache-2.0" +license = { text = "Apache-2.0" } readme = "README.md" repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml b/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml index d67ebb4ca8e2..db13e284486b 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml +++ b/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml @@ -3,7 +3,7 @@ name = "petstore_api" version = "1.0.0" description = "OpenAPI Petstore" authors = ["OpenAPI Generator Community "] -license = "Apache-2.0" +license = { text = "Apache-2.0" } readme = "README.md" repository = "https://GIT_HOST/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] diff --git a/samples/openapi3/client/petstore/python/pyproject.toml b/samples/openapi3/client/petstore/python/pyproject.toml index c5d3669a6ff9..a466656e8b6e 100644 --- a/samples/openapi3/client/petstore/python/pyproject.toml +++ b/samples/openapi3/client/petstore/python/pyproject.toml @@ -5,7 +5,7 @@ description = "OpenAPI Petstore" authors = [ {name = "OpenAPI Generator Community",email = "team@openapitools.org"}, ] -license = "Apache-2.0" +license = { text = "Apache-2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] requires-python = ">=3.9" From b31668391f2c70109c372e3c71e632bb2271a544 Mon Sep 17 00:00:00 2001 From: keepConcentration Date: Sun, 10 Aug 2025 11:45:54 +0900 Subject: [PATCH 3/5] Generate the samples (#21698) --- .../pyproject.toml | 2 +- samples/client/echo_api/python-pydantic-v1/pyproject.toml | 2 +- samples/client/echo_api/python/pyproject.toml | 2 +- .../client/petstore/python-pydantic-v1-aiohttp/pyproject.toml | 2 +- .../openapi3/client/petstore/python-pydantic-v1/pyproject.toml | 2 +- samples/openapi3/client/petstore/python/pyproject.toml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml index 25952c26ec86..fcf9c73b1528 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/pyproject.toml @@ -5,7 +5,7 @@ description = "Echo Server API" authors = [ {name = "OpenAPI Generator Community",email = "team@openapitools.org"}, ] -license = "Apache 2.0" +license = { text = "Apache 2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] requires-python = ">=3.9" diff --git a/samples/client/echo_api/python-pydantic-v1/pyproject.toml b/samples/client/echo_api/python-pydantic-v1/pyproject.toml index 192e7c548361..08cecd35678a 100644 --- a/samples/client/echo_api/python-pydantic-v1/pyproject.toml +++ b/samples/client/echo_api/python-pydantic-v1/pyproject.toml @@ -3,7 +3,7 @@ name = "openapi_client" version = "1.0.0" description = "Echo Server API" authors = ["OpenAPI Generator Community "] -license = "Apache 2.0" +license = { text = "Apache 2.0" } readme = "README.md" repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] diff --git a/samples/client/echo_api/python/pyproject.toml b/samples/client/echo_api/python/pyproject.toml index 25952c26ec86..fcf9c73b1528 100644 --- a/samples/client/echo_api/python/pyproject.toml +++ b/samples/client/echo_api/python/pyproject.toml @@ -5,7 +5,7 @@ description = "Echo Server API" authors = [ {name = "OpenAPI Generator Community",email = "team@openapitools.org"}, ] -license = "Apache 2.0" +license = { text = "Apache 2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] requires-python = ">=3.9" diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml index d65781e4a8a8..3afb571fa277 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml @@ -3,7 +3,7 @@ name = "petstore_api" version = "1.0.0" description = "OpenAPI Petstore" authors = ["OpenAPI Generator Community "] -license = "Apache-2.0" +license = { text = "Apache-2.0" } readme = "README.md" repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml b/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml index d67ebb4ca8e2..db13e284486b 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml +++ b/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml @@ -3,7 +3,7 @@ name = "petstore_api" version = "1.0.0" description = "OpenAPI Petstore" authors = ["OpenAPI Generator Community "] -license = "Apache-2.0" +license = { text = "Apache-2.0" } readme = "README.md" repository = "https://GIT_HOST/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] diff --git a/samples/openapi3/client/petstore/python/pyproject.toml b/samples/openapi3/client/petstore/python/pyproject.toml index c5d3669a6ff9..a466656e8b6e 100644 --- a/samples/openapi3/client/petstore/python/pyproject.toml +++ b/samples/openapi3/client/petstore/python/pyproject.toml @@ -5,7 +5,7 @@ description = "OpenAPI Petstore" authors = [ {name = "OpenAPI Generator Community",email = "team@openapitools.org"}, ] -license = "Apache-2.0" +license = { text = "Apache-2.0" } readme = "README.md" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] requires-python = ">=3.9" From 77cbc639872541ac7ed88014f2162ada13a679dd Mon Sep 17 00:00:00 2001 From: keepConcentration Date: Tue, 9 Sep 2025 22:59:09 +0900 Subject: [PATCH 4/5] Remove Python-Pydantic-v1 license format tests (#21619) --- .../python-pydantic-v1/pyproject.mustache | 2 +- .../PythonPydanticV1ClientCodegenTest.java | 42 ------------------- 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python-pydantic-v1/pyproject.mustache b/modules/openapi-generator/src/main/resources/python-pydantic-v1/pyproject.mustache index d1c934ee4ec8..8892d1566f32 100644 --- a/modules/openapi-generator/src/main/resources/python-pydantic-v1/pyproject.mustache +++ b/modules/openapi-generator/src/main/resources/python-pydantic-v1/pyproject.mustache @@ -3,7 +3,7 @@ name = "{{{packageName}}}" version = "{{{packageVersion}}}" description = "{{{appName}}}" authors = ["{{infoName}}{{^infoName}}OpenAPI Generator Community{{/infoName}} <{{infoEmail}}{{^infoEmail}}team@openapitools.org{{/infoEmail}}>"] -license = { text = "{{{licenseInfo}}}{{^licenseInfo}}Unlicense{{/licenseInfo}}" } +license = "{{{licenseInfo}}}{{^licenseInfo}}Unlicense{{/licenseInfo}}" readme = "README.md" repository = "https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}" keywords = ["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"] diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonPydanticV1ClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonPydanticV1ClientCodegenTest.java index df0e185b87dc..1c2fd629ce3b 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonPydanticV1ClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonPydanticV1ClientCodegenTest.java @@ -25,7 +25,6 @@ import io.swagger.v3.parser.core.models.ParseOptions; import io.swagger.v3.parser.util.SchemaTypeUtil; import org.openapitools.codegen.*; -import org.openapitools.codegen.config.CodegenConfigurator; import org.openapitools.codegen.languages.PythonPydanticV1ClientCodegen; import org.openapitools.codegen.languages.features.CXFServerFeatures; import org.testng.Assert; @@ -535,45 +534,4 @@ public void testInitFileImportsExports() throws Exception { assertFileContains(initFilePath, "from openapi_client.models.tag import Tag as Tag"); assertFileContains(initFilePath, "from openapi_client.models.user import User as User"); } - - @Test(description = "Verify pydantic-v1 always uses object notation for license") - public void testLicenseFormatInPyprojectToml() throws IOException { - File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); - output.deleteOnExit(); - - final CodegenConfigurator configurator = new CodegenConfigurator() - .setGeneratorName("python-pydantic-v1") - .setInputSpec("src/test/resources/bugs/issue_21619.yaml") - .setOutputDir(output.getAbsolutePath()) - .addAdditionalProperty("licenseInfo", "MIT"); - - DefaultGenerator generator = new DefaultGenerator(); - List files = generator.opts(configurator.toClientOptInput()).generate(); - files.forEach(File::deleteOnExit); - - TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "pyproject.toml")); - // python-pydantic-v1 always uses object notation regardless of poetry1 - TestUtils.assertFileContains(Paths.get(output.getAbsolutePath(), "pyproject.toml"), - "license = { text = \"MIT\" }"); - } - - @Test(description = "Verify pydantic-v1 uses default license when licenseInfo not provided") - public void testDefaultLicenseInPyprojectToml() throws IOException { - File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); - output.deleteOnExit(); - - final CodegenConfigurator configurator = new CodegenConfigurator() - .setGeneratorName("python-pydantic-v1") - .setInputSpec("src/test/resources/bugs/issue_21619.yaml") - .setOutputDir(output.getAbsolutePath()); - - DefaultGenerator generator = new DefaultGenerator(); - List files = generator.opts(configurator.toClientOptInput()).generate(); - files.forEach(File::deleteOnExit); - - TestUtils.assertFileExists(Paths.get(output.getAbsolutePath(), "pyproject.toml")); - // Should use default "Unlicense" - TestUtils.assertFileContains(Paths.get(output.getAbsolutePath(), "pyproject.toml"), - "license = { text = \"Unlicense\" }"); - } } From 8fe5f81728261aeac79e0797cc3bb0c3bc36685f Mon Sep 17 00:00:00 2001 From: keepConcentration Date: Tue, 9 Sep 2025 23:07:03 +0900 Subject: [PATCH 5/5] Revert license format to string in Python-Pydantic-v1 samples (#21619) --- samples/client/echo_api/python-pydantic-v1/pyproject.toml | 2 +- .../client/petstore/python-pydantic-v1-aiohttp/pyproject.toml | 2 +- .../openapi3/client/petstore/python-pydantic-v1/pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/client/echo_api/python-pydantic-v1/pyproject.toml b/samples/client/echo_api/python-pydantic-v1/pyproject.toml index 08cecd35678a..192e7c548361 100644 --- a/samples/client/echo_api/python-pydantic-v1/pyproject.toml +++ b/samples/client/echo_api/python-pydantic-v1/pyproject.toml @@ -3,7 +3,7 @@ name = "openapi_client" version = "1.0.0" description = "Echo Server API" authors = ["OpenAPI Generator Community "] -license = { text = "Apache 2.0" } +license = "Apache 2.0" readme = "README.md" repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "Echo Server API"] diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml index 3afb571fa277..d65781e4a8a8 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/pyproject.toml @@ -3,7 +3,7 @@ name = "petstore_api" version = "1.0.0" description = "OpenAPI Petstore" authors = ["OpenAPI Generator Community "] -license = { text = "Apache-2.0" } +license = "Apache-2.0" readme = "README.md" repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"] diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml b/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml index db13e284486b..d67ebb4ca8e2 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml +++ b/samples/openapi3/client/petstore/python-pydantic-v1/pyproject.toml @@ -3,7 +3,7 @@ name = "petstore_api" version = "1.0.0" description = "OpenAPI Petstore" authors = ["OpenAPI Generator Community "] -license = { text = "Apache-2.0" } +license = "Apache-2.0" readme = "README.md" repository = "https://GIT_HOST/GIT_USER_ID/GIT_REPO_ID" keywords = ["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"]