Skip to content

Commit 2020d96

Browse files
author
lseguin
committed
bugfix/generate_correct_setup_py_when_no_apis
1 parent 975f4d4 commit 2020d96

File tree

3 files changed

+58
-24
lines changed

3 files changed

+58
-24
lines changed

modules/openapi-generator/src/main/resources/python/setup.mustache

+17-24
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ from setuptools import setup, find_packages # noqa: H301
1313
NAME = "{{{projectName}}}"
1414
VERSION = "{{packageVersion}}"
1515
PYTHON_REQUIRES = ">= 3.8"
16-
{{#apiInfo}}
17-
{{#apis}}
18-
{{#-last}}
1916
REQUIRES = [
2017
"urllib3 >= 1.25.3, < 3.0.0",
2118
"python-dateutil >= 2.8.2",
@@ -33,25 +30,21 @@ REQUIRES = [
3330
"pydantic >= 2",
3431
"typing-extensions >= 4.7.1",
3532
]
36-
3733
setup(
38-
name=NAME,
39-
version=VERSION,
40-
description="{{appName}}",
41-
author="{{infoName}}{{^infoName}}OpenAPI Generator community{{/infoName}}",
42-
author_email="{{infoEmail}}{{^infoEmail}}[email protected]{{/infoEmail}}",
43-
url="{{packageUrl}}",
44-
keywords=["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"],
45-
install_requires=REQUIRES,
46-
packages=find_packages(exclude=["test", "tests"]),
47-
include_package_data=True,
48-
{{#licenseInfo}}license="{{.}}",
49-
{{/licenseInfo}}long_description_content_type='text/markdown',
50-
long_description="""\
51-
{{appDescription}}
52-
""", # noqa: E501
53-
package_data={"{{{packageName}}}": ["py.typed"]},
54-
)
55-
{{/-last}}
56-
{{/apis}}
57-
{{/apiInfo}}
34+
name=NAME,
35+
version=VERSION,
36+
description="{{appName}}",
37+
author="{{infoName}}{{^infoName}}OpenAPI Generator community{{/infoName}}",
38+
author_email="{{infoEmail}}{{^infoEmail}}[email protected]{{/infoEmail}}",
39+
url="{{packageUrl}}",
40+
keywords=["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"],
41+
install_requires=REQUIRES,
42+
packages=find_packages(exclude=["test", "tests"]),
43+
include_package_data=True,
44+
{{#licenseInfo}}license="{{.}}",
45+
{{/licenseInfo}}long_description_content_type='text/markdown',
46+
long_description="""\
47+
{{appDescription}}
48+
""", # noqa: E501
49+
package_data={"{{{packageName}}}": ["py.typed"]},
50+
)

modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.openapitools.codegen.*;
2929
import org.openapitools.codegen.languages.PythonClientCodegen;
3030
import org.openapitools.codegen.languages.features.CXFServerFeatures;
31+
32+
import static org.junit.jupiter.api.Assertions.assertNull;
3133
import static org.openapitools.codegen.TestUtils.assertFileContains;
3234
import static org.openapitools.codegen.TestUtils.assertFileExists;
3335
import org.openapitools.codegen.TestUtils;
@@ -541,4 +543,27 @@ public void testEnumPropertyWithQuotes() {
541543
Assert.assertEquals(codegen.toEnumValue("1.0", "float"), "1.0");
542544
Assert.assertEquals(codegen.toEnumValue("1", "int"), "1");
543545
}
546+
547+
@Test
548+
public void testHandleNoApis() throws IOException {
549+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
550+
output.deleteOnExit();
551+
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/no_apis.yaml");
552+
final DefaultGenerator defaultGenerator = new DefaultGenerator();
553+
final ClientOptInput clientOptInput = new ClientOptInput();
554+
clientOptInput.openAPI(openAPI);
555+
PythonClientCodegen pythonClientCodegen = new PythonClientCodegen();
556+
pythonClientCodegen.setOutputDir(output.getAbsolutePath());
557+
clientOptInput.config(pythonClientCodegen);
558+
defaultGenerator.opts(clientOptInput);
559+
560+
Map<String, File> files = defaultGenerator.generate().stream().collect(Collectors.toMap(File::getPath, Function.identity()));
561+
562+
File apiFile = files.get(Paths.get(output.getAbsolutePath(), "openapi_client", "api", "hello_example_api.py").toString());
563+
assertNull(apiFile);
564+
565+
File setupFile = files.get(Paths.get(output.getAbsolutePath(), "setup.py").toString());
566+
assertNotNull(setupFile);
567+
assertFileContains(setupFile.toPath(), "setup(");
568+
}
544569
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Example Hello API
4+
description: ''
5+
version: v1
6+
servers:
7+
- url: http://localhost
8+
description: Global Endpoint
9+
paths: {}
10+
components:
11+
schemas:
12+
HelloResponse:
13+
type: object
14+
properties:
15+
message:
16+
type: string

0 commit comments

Comments
 (0)