|
6 | 6 | import org.openapitools.codegen.config.CodegenConfigurator; |
7 | 7 | import org.openapitools.codegen.languages.RustAxumServerCodegen; |
8 | 8 | import org.testng.Assert; |
| 9 | +import org.testng.annotations.DataProvider; |
9 | 10 | import org.testng.annotations.Test; |
10 | 11 |
|
11 | 12 | import java.io.File; |
|
18 | 19 | import static org.openapitools.codegen.TestUtils.linearize; |
19 | 20 |
|
20 | 21 | public class RustAxumServerCodegenTest { |
| 22 | + @DataProvider(name = "additionalPropertiesSpecs") |
| 23 | + public Object[][] additionalPropertiesSpecs() { |
| 24 | + return new Object[][] { |
| 25 | + {"src/test/resources/3_0/rust-axum/additional-properties.yaml"}, |
| 26 | + {"src/test/resources/3_1/rust-axum/additional-properties.yaml"} |
| 27 | + }; |
| 28 | + } |
| 29 | + |
| 30 | + @Test(dataProvider = "additionalPropertiesSpecs") |
| 31 | + public void testAdditionalPropertiesFalse(String inputSpec) throws IOException { |
| 32 | + Path target = Files.createTempDirectory("test"); |
| 33 | + final CodegenConfigurator configurator = new CodegenConfigurator() |
| 34 | + .setGeneratorName("rust-axum") |
| 35 | + .setInputSpec(inputSpec) |
| 36 | + .setSkipOverwrite(false) |
| 37 | + .setOutputDir(target.toAbsolutePath().toString().replace("\\", "/")); |
| 38 | + List<File> files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); |
| 39 | + files.forEach(File::deleteOnExit); |
| 40 | + |
| 41 | + Path modelsPath = Path.of(target.toString(), "/src/models.rs"); |
| 42 | + TestUtils.assertFileExists(modelsPath); |
| 43 | + for (String model : List.of("ClosedObject", "ClosedNested", "ClosedOptional")) { |
| 44 | + TestUtils.assertFileContains(modelsPath, "#[serde(deny_unknown_fields)]\npub struct " + model + " {"); |
| 45 | + } |
| 46 | + for (String model : List.of("OpenObject", "UnspecifiedObject", "TypedAdditionalProperties")) { |
| 47 | + TestUtils.assertFileContains(modelsPath, "pub struct " + model + " {"); |
| 48 | + TestUtils.assertFileNotContains(modelsPath, "#[serde(deny_unknown_fields)]\npub struct " + model + " {"); |
| 49 | + } |
| 50 | + } |
| 51 | + |
21 | 52 | @Test |
22 | 53 | public void testObjectStructFieldIsPublic() throws IOException { |
23 | 54 | Path target = Files.createTempDirectory("test"); |
|
0 commit comments