Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ authors = [
]
{{/poetry1}}
{{#licenseInfo}}
{{#poetry1}}
license = "{{{licenseInfo}}}"
{{/poetry1}}
{{^poetry1}}
license = { text = "{{{licenseInfo}}}" }
{{/poetry1}}
{{/licenseInfo}}
readme = "README.md"
{{#poetry1}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<File> 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<File> 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<File> 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\"");
}
}
31 changes: 31 additions & 0 deletions modules/openapi-generator/src/test/resources/bugs/issue_21619.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion samples/client/echo_api/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion samples/openapi3/client/petstore/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading