|
7 | 7 | import io.swagger.v3.parser.core.models.ParseOptions;
|
8 | 8 | import java.util.HashMap;
|
9 | 9 | import java.util.function.Consumer;
|
| 10 | +import java.util.stream.Stream; |
10 | 11 | import org.apache.commons.io.FileUtils;
|
11 | 12 | import org.assertj.core.api.Assertions;
|
12 | 13 | import org.jetbrains.annotations.NotNull;
|
|
15 | 16 | import org.openapitools.codegen.DefaultGenerator;
|
16 | 17 | import org.openapitools.codegen.TestUtils;
|
17 | 18 | import org.openapitools.codegen.config.CodegenConfigurator;
|
18 |
| -import org.openapitools.codegen.java.assertions.JavaFileAssert; |
19 | 19 | import org.openapitools.codegen.kotlin.KotlinTestUtils;
|
20 | 20 | import org.openapitools.codegen.languages.KotlinSpringServerCodegen;
|
21 | 21 | import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
| 22 | +import org.openapitools.codegen.languages.features.DocumentationProviderFeatures; |
22 | 23 | import org.openapitools.codegen.languages.features.DocumentationProviderFeatures.AnnotationLibrary;
|
23 | 24 | import org.openapitools.codegen.languages.features.DocumentationProviderFeatures.DocumentationProvider;
|
24 | 25 | import org.testng.Assert;
|
| 26 | +import org.testng.annotations.DataProvider; |
25 | 27 | import org.testng.annotations.Test;
|
26 | 28 |
|
27 | 29 | import java.io.File;
|
@@ -1232,6 +1234,79 @@ public void testValidationsInQueryParams_issue21238_Api_Delegate() throws IOExce
|
1232 | 1234 | "@NotNull", "@Valid", "@Pattern(regexp=\"^[a-zA-Z0-9]+[a-zA-Z0-9\\\\.\\\\-_]*[a-zA-Z0-9]+$\")");
|
1233 | 1235 | }
|
1234 | 1236 |
|
| 1237 | + @DataProvider |
| 1238 | + public Object[][] issue17997DocumentationProviders() { |
| 1239 | + return new Object[][]{ |
| 1240 | + {DocumentationProviderFeatures.DocumentationProvider.SPRINGDOC.name(), |
| 1241 | + (Consumer<Path>) outputPath -> |
| 1242 | + assertFileContains( |
| 1243 | + outputPath, |
| 1244 | + "allowableValues = [\"0\", \"1\"], defaultValue = \"0\"", |
| 1245 | + "@PathVariable" |
| 1246 | + ), |
| 1247 | + (Consumer<Path>) outputPath -> |
| 1248 | + assertFileContains( |
| 1249 | + outputPath, |
| 1250 | + "allowableValues = [\"sleeping\", \"awake\"]", "@PathVariable", |
| 1251 | + "@PathVariable" |
| 1252 | + ) |
| 1253 | + }, |
| 1254 | + {DocumentationProviderFeatures.DocumentationProvider.SPRINGFOX.name(), |
| 1255 | + (Consumer<Path>) outputPath -> |
| 1256 | + assertFileContains( |
| 1257 | + outputPath, |
| 1258 | + "allowableValues = \"0, 1\", defaultValue = \"0\"", |
| 1259 | + "@PathVariable" |
| 1260 | + ), |
| 1261 | + (Consumer<Path>) outputPath -> |
| 1262 | + assertFileContains( |
| 1263 | + outputPath, |
| 1264 | + "allowableValues = \"sleeping, awake\"", "@PathVariable", |
| 1265 | + "@PathVariable" |
| 1266 | + ) |
| 1267 | + } |
| 1268 | + }; |
| 1269 | + } |
| 1270 | + |
| 1271 | + @Test(dataProvider = "issue17997DocumentationProviders") |
| 1272 | + public void testDocumentationAnnotationInPathParams_Issue17997( |
| 1273 | + String documentProvider, |
| 1274 | + Consumer<Path> intEnumAssertFunction, |
| 1275 | + Consumer<Path> stringEnumAssertFunction |
| 1276 | + ) throws IOException { |
| 1277 | + Map<String, Object> additionalProperties = new HashMap<>(); |
| 1278 | + additionalProperties.put(DOCUMENTATION_PROVIDER, documentProvider); |
| 1279 | + |
| 1280 | + Map<String, String> generatorPropertyDefaults = new HashMap<>(); |
| 1281 | + generatorPropertyDefaults.put(CodegenConstants.MODEL_TESTS, "false"); |
| 1282 | + generatorPropertyDefaults.put(CodegenConstants.MODEL_DOCS, "false"); |
| 1283 | + generatorPropertyDefaults.put(CodegenConstants.APIS, "true"); |
| 1284 | + |
| 1285 | + Map<String, File> files = generateFromContract( |
| 1286 | + "src/test/resources/3_0/issue_6762.yaml", |
| 1287 | + additionalProperties, |
| 1288 | + generatorPropertyDefaults |
| 1289 | + ); |
| 1290 | + |
| 1291 | + Stream.of( |
| 1292 | + "ZebrasApiController.kt", |
| 1293 | + "GiraffesApiController.kt" |
| 1294 | + ).forEach(filename -> { |
| 1295 | + File file = files.get(filename); |
| 1296 | + assertThat(file).isNotNull(); |
| 1297 | + intEnumAssertFunction.accept(file.toPath()); |
| 1298 | + }); |
| 1299 | + |
| 1300 | + Stream.of( |
| 1301 | + "BearsApiController.kt", |
| 1302 | + "CamelsApiController.kt" |
| 1303 | + ).forEach(filename -> { |
| 1304 | + File file = files.get(filename); |
| 1305 | + assertThat(file).isNotNull(); |
| 1306 | + stringEnumAssertFunction.accept(file.toPath()); |
| 1307 | + }); |
| 1308 | + } |
| 1309 | + |
1235 | 1310 | private Map<String, File> generateFromContract(String url) throws IOException {
|
1236 | 1311 | return generateFromContract(url, new HashMap<>(), new HashMap<>());
|
1237 | 1312 | }
|
|
0 commit comments