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

Use camelCase in AsObject definition #430

Merged
merged 3 commits into from
Jan 8, 2019
Merged
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
23 changes: 22 additions & 1 deletion javascript/net/grpc/web/grpc_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ string JSFieldName(const FieldDescriptor *desc)
return js_field_name;
}

// Like ToUpperCamel except the first letter is not converted.
string ToCamelCase(const std::vector<string>& words)
{
if (words.size() == 0) {
return "";
}
string result = words[0];
return result + ToUpperCamel(std::vector<string>(words.begin()+1, words.begin()+words.size()));
}

// Like JSFieldName, but with first letter not uppercased
string CamelCaseJSFieldName(const FieldDescriptor *desc)
{
string js_field_name = ToCamelCase(ParseLowerUnderscore(desc->name()));
if (desc->is_repeated())
{
js_field_name += "List";
}
return js_field_name;
}

// Returns the name of the message with a leading dot and taking into account
// nesting, for example ".OuterMessage.InnerMessage", or returns empty if
// descriptor is null. This function does not handle namespacing, only message
Expand Down Expand Up @@ -669,7 +690,7 @@ void PrintProtoDtsMessage(Printer *printer, const Descriptor *desc, string prefi
printer->Print("export type AsObject = {\n");
printer->Indent();
for (int i = 0; i < desc->field_count(); i++) {
vars["js_field_name"] = JSFieldName(desc->field(i));
vars["js_field_name"] = CamelCaseJSFieldName(desc->field(i));
vars["js_field_type"] = JSFieldType(desc->field(i));
printer->Print(vars, "$js_field_name$: $js_field_type$;\n");
}
Expand Down