|
7 | 7 | import io.swagger.v3.oas.models.media.Schema; |
8 | 8 | import io.swagger.v3.oas.models.responses.ApiResponse; |
9 | 9 | import io.swagger.v3.oas.models.responses.ApiResponses; |
| 10 | +import java.util.Arrays; |
| 11 | +import java.util.Collections; |
| 12 | +import java.util.List; |
10 | 13 | import org.openapitools.codegen.CodegenOperation; |
| 14 | +import org.openapitools.codegen.CodegenParameter; |
11 | 15 | import org.openapitools.codegen.TestUtils; |
12 | 16 | import org.openapitools.codegen.languages.TypeScriptNestjsClientCodegen; |
| 17 | +import org.openapitools.codegen.model.OperationMap; |
| 18 | +import org.openapitools.codegen.model.OperationsMap; |
13 | 19 | import org.openapitools.codegen.typescript.TypeScriptGroups; |
14 | 20 | import org.testng.Assert; |
15 | 21 | import org.testng.annotations.Test; |
@@ -134,4 +140,41 @@ public void testSchema() { |
134 | 140 | Assert.assertEquals(schemaType, "SchemaOne | SchemaTwo | SchemaThree"); |
135 | 141 | } |
136 | 142 |
|
| 143 | + @Test |
| 144 | + public void testPathPropertyName() { |
| 145 | + TypeScriptNestjsClientCodegen codegen = new TypeScriptNestjsClientCodegen(); |
| 146 | + |
| 147 | + CodegenOperation codegenOperation = new CodegenOperation(); |
| 148 | + |
| 149 | + CodegenParameter pathParam1 = createPathParam("pathParam1", "path_param1"); |
| 150 | + CodegenParameter pathParam2 = createPathParam("pathParam2", "pathParam2"); |
| 151 | + |
| 152 | + codegenOperation.httpMethod = "GET"; |
| 153 | + codegenOperation.path = "test/{path_param1}/{pathParam2}"; |
| 154 | + codegenOperation.allParams.addAll(Arrays.asList(pathParam1, pathParam2)); |
| 155 | + codegenOperation.pathParams.addAll(Arrays.asList(pathParam1, pathParam2)); |
| 156 | + |
| 157 | + OperationMap operations = new OperationMap(); |
| 158 | + operations.setOperation(codegenOperation); |
| 159 | + operations.setClassname("TestService"); |
| 160 | + |
| 161 | + OperationsMap objs = new OperationsMap(); |
| 162 | + objs.setOperation(operations); |
| 163 | + objs.setImports(List.of()); |
| 164 | + |
| 165 | + var res = codegen.postProcessOperationsWithModels(objs, Collections.emptyList()); |
| 166 | + |
| 167 | + Assert.assertEquals(res.getOperations().getOperation().get(0).path, |
| 168 | + "test/${encodeURIComponent(String(pathParam1))}/${encodeURIComponent(String(pathParam2))}"); |
| 169 | + } |
| 170 | + |
| 171 | + private CodegenParameter createPathParam(String paramName, String baseName) { |
| 172 | + CodegenParameter codegenParameter = new CodegenParameter(); |
| 173 | + codegenParameter.paramName = paramName; |
| 174 | + codegenParameter.baseName = baseName; |
| 175 | + codegenParameter.dataType = "String"; |
| 176 | + codegenParameter.isPathParam = true; |
| 177 | + return codegenParameter; |
| 178 | + } |
| 179 | + |
137 | 180 | } |
0 commit comments