|
21 | 21 | import io.swagger.v3.oas.models.Components;
|
22 | 22 | import io.swagger.v3.oas.models.OpenAPI;
|
23 | 23 | import io.swagger.v3.oas.models.Operation;
|
| 24 | +import io.swagger.v3.oas.models.PathItem; |
24 | 25 | import io.swagger.v3.oas.models.media.ArraySchema;
|
25 | 26 | import io.swagger.v3.oas.models.media.Content;
|
26 | 27 | import io.swagger.v3.oas.models.media.MediaType;
|
|
37 | 38 | import org.testng.Assert;
|
38 | 39 | import org.testng.annotations.Test;
|
39 | 40 |
|
40 |
| -import java.lang.reflect.Method; |
41 |
| -import java.util.*; |
| 41 | +import java.util.Arrays; |
| 42 | +import java.util.Collections; |
| 43 | +import java.util.HashMap; |
| 44 | +import java.util.HashSet; |
| 45 | +import java.util.List; |
| 46 | +import java.util.Locale; |
| 47 | +import java.util.Map; |
| 48 | +import java.util.Set; |
42 | 49 | import java.util.stream.Collectors;
|
43 | 50 |
|
44 | 51 |
|
@@ -224,8 +231,8 @@ public void testConsistentParameterNameAfterUniquenessRename() throws Exception
|
224 | 231 | .responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("OK")));
|
225 | 232 |
|
226 | 233 | DefaultCodegen codegen = new DefaultCodegen();
|
227 |
| - CodegenOperation co = codegen.fromOperation("p/", "get", operation, Collections.emptyMap()); |
228 |
| - Assert.assertEquals(co.path, "p/"); |
| 234 | + CodegenOperation co = codegen.fromOperation("/some/path", "get", operation, Collections.emptyMap()); |
| 235 | + Assert.assertEquals(co.path, "/some/path"); |
229 | 236 | Assert.assertEquals(co.allParams.size(), 2);
|
230 | 237 | List<String> allParamsNames = co.allParams.stream().map(p -> p.paramName).collect(Collectors.toList());
|
231 | 238 | Assert.assertTrue(allParamsNames.contains("myparam"));
|
@@ -500,6 +507,21 @@ public void testCallbacks() {
|
500 | 507 | });
|
501 | 508 | }
|
502 | 509 |
|
| 510 | + @Test |
| 511 | + public void testLeadingSlashIsAddedIfMissing() { |
| 512 | + OpenAPI openAPI = TestUtils.createOpenAPI(); |
| 513 | + Operation operation1 = new Operation().operationId("op1").responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK"))); |
| 514 | + openAPI.path("/here", new PathItem().get(operation1)); |
| 515 | + Operation operation2 = new Operation().operationId("op2").responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK"))); |
| 516 | + openAPI.path("some/path", new PathItem().get(operation2)); |
| 517 | + final DefaultCodegen codegen = new DefaultCodegen(); |
| 518 | + |
| 519 | + CodegenOperation co1 = codegen.fromOperation("/here", "get", operation2, ModelUtils.getSchemas(openAPI), openAPI); |
| 520 | + Assert.assertEquals(co1.path, "/here"); |
| 521 | + CodegenOperation co2 = codegen.fromOperation("some/path", "get", operation2, ModelUtils.getSchemas(openAPI), openAPI); |
| 522 | + Assert.assertEquals(co2.path, "/some/path"); |
| 523 | + } |
| 524 | + |
503 | 525 | private void verifyPersonDiscriminator(CodegenDiscriminator discriminator) {
|
504 | 526 | CodegenDiscriminator test = new CodegenDiscriminator();
|
505 | 527 | test.setPropertyName("$_type");
|
|
0 commit comments