mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +00:00
Swift3 enum: number variable names fix (#5060)
* Swift3 enum: number variable names fix Swift3 generator: added 'number' prefix to enum variable names that start with a number * Fixed Swift3 enum variable names starting with number (prefixed with '_') and added test cases * Swift3 enum var names: made sure to keep the next word after a number in lower case
This commit is contained in:
parent
4706f4da3e
commit
d5cb70f03e
@ -521,6 +521,15 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
|
||||
return "empty";
|
||||
}
|
||||
|
||||
Pattern startWithNumberPattern = Pattern.compile("^\\d+");
|
||||
Matcher startWithNumberMatcher = startWithNumberPattern.matcher(name);
|
||||
if (startWithNumberMatcher.find()) {
|
||||
String startingNumbers = startWithNumberMatcher.group(0);
|
||||
String nameWithoutStartingNumbers = name.substring(startingNumbers.length());
|
||||
|
||||
return "_" + startingNumbers + camelize(nameWithoutStartingNumbers, true);
|
||||
}
|
||||
|
||||
// for symbol, e.g. $, #
|
||||
if (getSymbolName(name) != null) {
|
||||
return camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase()), true);
|
||||
|
@ -63,6 +63,13 @@ public class Swift3CodegenTest {
|
||||
Assert.assertEquals(swiftCodegen.toEnumVarName("entry_name", null), "entryName");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartingWithNumber() throws Exception {
|
||||
Assert.assertEquals(swiftCodegen.toEnumVarName("123EntryName", null), "_123entryName");
|
||||
Assert.assertEquals(swiftCodegen.toEnumVarName("123Entry_name", null), "_123entryName");
|
||||
Assert.assertEquals(swiftCodegen.toEnumVarName("123EntryName123", null), "_123entryName123");
|
||||
}
|
||||
|
||||
@Test(description = "returns NSData when response format is binary")
|
||||
public void binaryDataTest() {
|
||||
final Swagger model = new SwaggerParser().read("src/test/resources/2_0/binaryDataTest.json");
|
||||
|
Loading…
Reference in New Issue
Block a user