camelize name in nim (#9255)

This commit is contained in:
William Cheng 2021-04-14 10:14:59 +08:00 committed by GitHub
parent b4ea00ed42
commit 1b63822501
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -31,6 +31,8 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
import static org.openapitools.codegen.utils.StringUtils.camelize;
public class NimClientCodegen extends DefaultCodegen implements CodegenConfig {
final Logger LOGGER = LoggerFactory.getLogger(NimClientCodegen.class);
@ -297,14 +299,32 @@ public class NimClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String toVarName(String name) {
if (isReservedWord(name)) {
name = escapeReservedWord(name);
// sanitize name
name = sanitizeName(name, "\\W-[\\$]"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
if ("_".equals(name)) {
name = "_u";
}
// numbers are not allowed at the beginning
if (name.matches("^\\d.*")) {
name = "`" + name + "`";
}
// if it's all uppper case, do nothing
if (name.matches("^[A-Z0-9_]*$")) {
return name;
}
// camelize (lower first character) the variable name
// pet_id => petId
name = camelize(name, true);
// for reserved word or word starting with number, append _
if (isReservedWord(name)) {
name = escapeReservedWord(name);
}
return name;
}

View File

@ -45,9 +45,9 @@ proc addPet*(httpClient: HttpClient, body: Pet): Response =
httpClient.post(basepath & "/pet", $(%body))
proc deletePet*(httpClient: HttpClient, petId: int64, api_key: string): Response =
proc deletePet*(httpClient: HttpClient, petId: int64, apiKey: string): Response =
## Deletes a pet
httpClient.headers["api_key"] = api_key
httpClient.headers["api_key"] = apiKey
httpClient.delete(basepath & fmt"/pet/{petId}")