Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ public String toOperationId(String operationId) {
throw new RuntimeException("Empty method name (operationId) not allowed");
}

// method name cannot use reserved keyword, e.g. return
// append _ at the beginning, e.g. _return
if (isReservedWord(operationId)) {
// method name cannot use reserved keyword or word starting with number, e.g. return or 123return
// append _ at the beginning, e.g. _return or _123return
if (isReservedWord(operationId) || operationId.matches("^\\d.*")) {
return escapeReservedWord(camelize(sanitizeName(operationId), true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
import org.junit.Assert;
import org.junit.Test;
import org.openapitools.codegen.languages.TypeScriptAngularClientCodegen;
import org.openapitools.codegen.TestUtils;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import org.openapitools.codegen.CodegenOperation;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.responses.ApiResponses;

public class TypeScriptAngularClientCodegenTest {
@Test
Expand All @@ -14,4 +21,18 @@ public void testModelFileSuffix() {

Assert.assertEquals(codegen.toModelFilename("testName"), "testNameMySuffix");
}

@Test
public void testOperationIdParser() {
OpenAPI openAPI = TestUtils.createOpenAPI();
Operation operation1 = new Operation().operationId("123_test_@#$%_special_tags").responses(new ApiResponses().addApiResponse("201", new ApiResponse().description("OK")));
openAPI.path("another-fake/dummy/", new PathItem().get(operation1));
final TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
codegen.setOpenAPI(openAPI);

CodegenOperation co1 = codegen.fromOperation("/another-fake/dummy/", "get", operation1, null);
org.testng.Assert.assertEquals(co1.operationId, "_123testSpecialTags");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,31 @@ public void mapModelTest() {
Assert.assertEquals(cm.additionalPropertiesType, "Children");
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
}

@Test(description = "convert a model with a name starting with decimal")
public void beginDecimalNameTest() {
final Schema schema = new Schema()
.description("a model with a name starting with decimal")
.addProperties("1list", new StringSchema())
.addRequiredItem("1list");
final DefaultCodegen codegen = new TypeScriptAngularClientCodegen();
OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
codegen.setOpenAPI(openAPI);
final CodegenModel cm = codegen.fromModel("sample", schema);

Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.vars.size(), 1);

final CodegenProperty property = cm.vars.get(0);
Assert.assertEquals(property.baseName, "1list");
Assert.assertEquals(property.dataType, "string");
Assert.assertEquals(property.name, "_1list");
Assert.assertEquals(property.defaultValue, "undefined");
Assert.assertEquals(property.baseType, "string");
Assert.assertFalse(property.hasMore);
Assert.assertTrue(property.required);
Assert.assertFalse(property.isContainer);
}

}