|
21 | 21 | import io.swagger.v3.oas.models.Operation;
|
22 | 22 | import io.swagger.v3.oas.models.media.*;
|
23 | 23 | import org.openapitools.codegen.*;
|
| 24 | +import org.openapitools.codegen.config.CodegenConfigurator; |
24 | 25 | import org.openapitools.codegen.languages.PythonClientCodegen;
|
25 | 26 | import org.openapitools.codegen.utils.ModelUtils;
|
26 | 27 | import org.testng.Assert;
|
27 | 28 | import org.testng.annotations.Test;
|
28 | 29 |
|
| 30 | +import java.io.File; |
29 | 31 | import java.io.IOException;
|
30 | 32 | import java.nio.charset.StandardCharsets;
|
| 33 | +import java.nio.file.Files; |
| 34 | +import java.nio.file.Path; |
| 35 | +import java.util.Collections; |
| 36 | +import java.util.List; |
| 37 | +import java.util.Map; |
31 | 38 |
|
32 | 39 | @SuppressWarnings("static-method")
|
33 | 40 | public class PythonClientTest {
|
@@ -116,4 +123,45 @@ private void testEndpointExampleValue(String endpoint, String specFilePath, Stri
|
116 | 123 |
|
117 | 124 | }
|
118 | 125 |
|
| 126 | + @Test |
| 127 | + public void testApiTestsNotGenerated() throws Exception { |
| 128 | + File output = Files.createTempDirectory("test").toFile(); |
| 129 | + |
| 130 | + Map<String, String> globalProperties = Collections.singletonMap("apiTests", "false"); |
| 131 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 132 | + .setGlobalProperties(globalProperties) |
| 133 | + .setGeneratorName("python") |
| 134 | + .setInputSpec("src/test/resources/3_0/petstore.yaml") |
| 135 | + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); |
| 136 | + |
| 137 | + final ClientOptInput clientOptInput = configurator.toClientOptInput(); |
| 138 | + DefaultGenerator generator = new DefaultGenerator(); |
| 139 | + List<File> files = generator.opts(clientOptInput).generate(); |
| 140 | + Assert.assertTrue(files.size() > 0); |
| 141 | + |
| 142 | + Path pathThatShouldNotExist = output.toPath().resolve("openapi_client/test/test_paths"); |
| 143 | + Assert.assertFalse(Files.isDirectory(pathThatShouldNotExist)); |
| 144 | + output.deleteOnExit(); |
| 145 | + } |
| 146 | + |
| 147 | + @Test |
| 148 | + public void testApisNotGenerated() throws Exception { |
| 149 | + File output = Files.createTempDirectory("test").toFile(); |
| 150 | + |
| 151 | + Map<String, String> globalProperties = Collections.singletonMap("models", ""); |
| 152 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 153 | + .setGlobalProperties(globalProperties) |
| 154 | + .setGeneratorName("python") |
| 155 | + .setInputSpec("src/test/resources/3_0/petstore.yaml") |
| 156 | + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); |
| 157 | + |
| 158 | + final ClientOptInput clientOptInput = configurator.toClientOptInput(); |
| 159 | + DefaultGenerator generator = new DefaultGenerator(); |
| 160 | + List<File> files = generator.opts(clientOptInput).generate(); |
| 161 | + Assert.assertTrue(files.size() > 0); |
| 162 | + |
| 163 | + Path pathThatShouldNotExist = output.toPath().resolve("openapi_client/paths"); |
| 164 | + Assert.assertFalse(Files.isDirectory(pathThatShouldNotExist)); |
| 165 | + output.deleteOnExit(); |
| 166 | + } |
119 | 167 | }
|
0 commit comments