Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nim] camelize names #9255

Merged
merged 1 commit into from
Apr 14, 2021
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 @@ -31,6 +31,8 @@
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);

Expand Down Expand Up @@ -297,14 +299,32 @@ public String getTypeDeclaration(Schema p) {

@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;
}

Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/nim/petstore/apis/api_pet.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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}")


Expand Down