Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][PYTHON] fix setup.py when no paths are specified #20098

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -13,9 +13,6 @@ from setuptools import setup, find_packages # noqa: H301
NAME = "{{{projectName}}}"
VERSION = "{{packageVersion}}"
PYTHON_REQUIRES = ">= 3.8"
{{#apiInfo}}
{{#apis}}
{{#-last}}
REQUIRES = [
"urllib3 >= 1.25.3, < 3.0.0",
"python-dateutil >= 2.8.2",
Expand Down Expand Up @@ -51,7 +48,4 @@ setup(
{{appDescription}}
""", # noqa: E501
package_data={"{{{packageName}}}": ["py.typed"]},
)
{{/-last}}
{{/apis}}
{{/apiInfo}}
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.PythonClientCodegen;
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.assertFileExists;
import org.openapitools.codegen.TestUtils;
Expand Down Expand Up @@ -541,4 +543,27 @@ public void testEnumPropertyWithQuotes() {
Assert.assertEquals(codegen.toEnumValue("1.0", "float"), "1.0");
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(");
}
}
16 changes: 16 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/no_apis.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
Echo Server API
""", # noqa: E501
package_data={"openapi_client": ["py.typed"]},
)
)
2 changes: 1 addition & 1 deletion samples/client/echo_api/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
Echo Server API
""", # noqa: E501
package_data={"openapi_client": ["py.typed"]},
)
)
2 changes: 1 addition & 1 deletion samples/openapi3/client/petstore/python-aiohttp/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
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
package_data={"petstore_api": ["py.typed"]},
)
)
2 changes: 1 addition & 1 deletion samples/openapi3/client/petstore/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
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
package_data={"petstore_api": ["py.typed"]},
)
)