bugfix: generate correct setup.pi when no paths are specified (#20098)

This commit is contained in:
loic-seguin 2024-12-17 03:58:26 +01:00 committed by GitHub
parent e87c4ea6c0
commit b01c8be47f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 46 additions and 11 deletions

View File

@ -13,9 +13,6 @@ from setuptools import setup, find_packages # noqa: H301
NAME = "{{{projectName}}}" NAME = "{{{projectName}}}"
VERSION = "{{packageVersion}}" VERSION = "{{packageVersion}}"
PYTHON_REQUIRES = ">= 3.8" PYTHON_REQUIRES = ">= 3.8"
{{#apiInfo}}
{{#apis}}
{{#-last}}
REQUIRES = [ REQUIRES = [
"urllib3 >= 1.25.3, < 3.0.0", "urllib3 >= 1.25.3, < 3.0.0",
"python-dateutil >= 2.8.2", "python-dateutil >= 2.8.2",
@ -51,7 +48,4 @@ setup(
{{appDescription}} {{appDescription}}
""", # noqa: E501 """, # noqa: E501
package_data={"{{{packageName}}}": ["py.typed"]}, package_data={"{{{packageName}}}": ["py.typed"]},
) )
{{/-last}}
{{/apis}}
{{/apiInfo}}

View File

@ -28,6 +28,8 @@ import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.openapitools.codegen.*; import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.PythonClientCodegen; import org.openapitools.codegen.languages.PythonClientCodegen;
import org.openapitools.codegen.languages.features.CXFServerFeatures; import org.openapitools.codegen.languages.features.CXFServerFeatures;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.openapitools.codegen.TestUtils.assertFileContains; import static org.openapitools.codegen.TestUtils.assertFileContains;
import static org.openapitools.codegen.TestUtils.assertFileExists; import static org.openapitools.codegen.TestUtils.assertFileExists;
import org.openapitools.codegen.TestUtils; import org.openapitools.codegen.TestUtils;
@ -541,4 +543,27 @@ public class PythonClientCodegenTest {
Assert.assertEquals(codegen.toEnumValue("1.0", "float"), "1.0"); Assert.assertEquals(codegen.toEnumValue("1.0", "float"), "1.0");
Assert.assertEquals(codegen.toEnumValue("1", "int"), "1"); Assert.assertEquals(codegen.toEnumValue("1", "int"), "1");
} }
@Test
public void testHandleNoApis() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/no_apis.yaml");
final DefaultGenerator defaultGenerator = new DefaultGenerator();
final ClientOptInput clientOptInput = new ClientOptInput();
clientOptInput.openAPI(openAPI);
PythonClientCodegen pythonClientCodegen = new PythonClientCodegen();
pythonClientCodegen.setOutputDir(output.getAbsolutePath());
clientOptInput.config(pythonClientCodegen);
defaultGenerator.opts(clientOptInput);
Map<String, File> files = defaultGenerator.generate().stream().collect(Collectors.toMap(File::getPath, Function.identity()));
File apiFile = files.get(Paths.get(output.getAbsolutePath(), "openapi_client", "api", "hello_example_api.py").toString());
assertNull(apiFile);
File setupFile = files.get(Paths.get(output.getAbsolutePath(), "setup.py").toString());
assertNotNull(setupFile);
assertFileContains(setupFile.toPath(), "setup(");
}
} }

View File

@ -0,0 +1,16 @@
openapi: 3.0.3
info:
title: Example Hello API
description: ''
version: v1
servers:
- url: http://localhost
description: Global Endpoint
paths: {}
components:
schemas:
HelloResponse:
type: object
properties:
message:
type: string

View File

@ -48,4 +48,4 @@ setup(
Echo Server API Echo Server API
""", # noqa: E501 """, # noqa: E501
package_data={"openapi_client": ["py.typed"]}, package_data={"openapi_client": ["py.typed"]},
) )

View File

@ -48,4 +48,4 @@ setup(
Echo Server API Echo Server API
""", # noqa: E501 """, # noqa: E501
package_data={"openapi_client": ["py.typed"]}, package_data={"openapi_client": ["py.typed"]},
) )

View File

@ -51,4 +51,4 @@ setup(
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \&quot; \\ This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \&quot; \\
""", # noqa: E501 """, # noqa: E501
package_data={"petstore_api": ["py.typed"]}, package_data={"petstore_api": ["py.typed"]},
) )

View File

@ -49,4 +49,4 @@ setup(
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \&quot; \\ This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \&quot; \\
""", # noqa: E501 """, # noqa: E501
package_data={"petstore_api": ["py.typed"]}, package_data={"petstore_api": ["py.typed"]},
) )