|
| 1 | +package org.openapitools.codegen.json; |
| 2 | + |
| 3 | +import org.openapitools.codegen.ClientOptInput; |
| 4 | +import org.openapitools.codegen.DefaultGenerator; |
| 5 | +import org.openapitools.codegen.config.CodegenConfigurator; |
| 6 | +import org.openapitools.codegen.languages.OpenAPIGenerator; |
| 7 | +import org.testng.annotations.Test; |
| 8 | + |
| 9 | +import java.io.File; |
| 10 | +import java.nio.file.Files; |
| 11 | +import java.nio.file.Paths; |
| 12 | +import java.util.HashMap; |
| 13 | +import java.util.Map; |
| 14 | + |
| 15 | +import static org.openapitools.codegen.TestUtils.assertFileContains; |
| 16 | + |
| 17 | +public class JsonGeneratorTest { |
| 18 | + |
| 19 | + @Test |
| 20 | + public void testGeneratePing() throws Exception { |
| 21 | + Map<String, Object> properties = new HashMap<>(); |
| 22 | + |
| 23 | + File output = Files.createTempDirectory("test").toFile(); |
| 24 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 25 | + |
| 26 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 27 | + .setGeneratorName("openapi") |
| 28 | + .setAdditionalProperties(properties) |
| 29 | + .setInputSpec("src/test/resources/3_0/ping.yaml") |
| 30 | + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); |
| 31 | + |
| 32 | + final ClientOptInput clientOptInput = configurator.toClientOptInput(); |
| 33 | + DefaultGenerator generator = new DefaultGenerator(); |
| 34 | + generator.opts(clientOptInput).generate(); |
| 35 | + assertFileContains(Paths.get(outputPath + "/openapi.json")); |
| 36 | + assertFileContains(Paths.get(outputPath + "/README.md")); |
| 37 | + assertFileContains(Paths.get(outputPath + "/.openapi-generator-ignore")); |
| 38 | + assertFileContains(Paths.get(outputPath + "/.openapi-generator/FILES")); |
| 39 | + assertFileContains(Paths.get(outputPath + "/.openapi-generator/VERSION")); |
| 40 | + |
| 41 | + output.deleteOnExit(); |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testGeneratePingOtherOutputFile() throws Exception { |
| 47 | + Map<String, Object> properties = new HashMap<>(); |
| 48 | + properties.put(OpenAPIGenerator.OUTPUT_NAME, "ping.json"); |
| 49 | + |
| 50 | + File output = Files.createTempDirectory("test").toFile(); |
| 51 | + String outputPath = output.getAbsolutePath().replace('\\', '/'); |
| 52 | + |
| 53 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 54 | + .setGeneratorName("openapi") |
| 55 | + .setAdditionalProperties(properties) |
| 56 | + .setInputSpec("src/test/resources/3_0/ping.yaml") |
| 57 | + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); |
| 58 | + |
| 59 | + final ClientOptInput clientOptInput = configurator.toClientOptInput(); |
| 60 | + DefaultGenerator generator = new DefaultGenerator(); |
| 61 | + generator.opts(clientOptInput).generate(); |
| 62 | + assertFileContains(Paths.get(outputPath + "/ping.json")); |
| 63 | + assertFileContains(Paths.get(outputPath + "/README.md")); |
| 64 | + assertFileContains(Paths.get(outputPath + "/.openapi-generator-ignore")); |
| 65 | + assertFileContains(Paths.get(outputPath + "/.openapi-generator/FILES")); |
| 66 | + assertFileContains(Paths.get(outputPath + "/.openapi-generator/VERSION")); |
| 67 | + |
| 68 | + output.deleteOnExit(); |
| 69 | + } |
| 70 | +} |
0 commit comments