Skip to content

Commit d5b1146

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

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

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

+1-7
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",
@@ -51,7 +48,4 @@ setup(
5148
{{appDescription}}
5249
""", # noqa: E501
5350
package_data={"{{{packageName}}}": ["py.typed"]},
54-
)
55-
{{/-last}}
56-
{{/apis}}
57-
{{/apiInfo}}
51+
)

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

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
Echo Server API
4949
""", # noqa: E501
5050
package_data={"openapi_client": ["py.typed"]},
51-
)
51+
)

samples/client/echo_api/python/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
Echo Server API
4949
""", # noqa: E501
5050
package_data={"openapi_client": ["py.typed"]},
51-
)
51+
)

samples/openapi3/client/petstore/python-aiohttp/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@
5151
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; \\
5252
""", # noqa: E501
5353
package_data={"petstore_api": ["py.typed"]},
54-
)
54+
)

samples/openapi3/client/petstore/python/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@
4949
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; \\
5050
""", # noqa: E501
5151
package_data={"petstore_api": ["py.typed"]},
52-
)
52+
)

0 commit comments

Comments
 (0)