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

feat: reduce possibility of name conflicts #682

Merged
merged 1 commit into from
Aug 28, 2020
Merged

Conversation

alexander-fenster
Copy link
Contributor

@alexander-fenster alexander-fenster commented Aug 28, 2020

This PR introduces a namer that, being a part of the template, makes sure that the generated extra method (such as FooAsync for method Foo, or checkFooProgress for long running method Foo) do not conflict with existing RPCs having the same names.

Implementation: a template may provide a JS file namer.js that will be loaded by the generator during its runtime and passed back to the template, so it could use the logic in JS to resolve name conflicts.

Let's assume the proto has a long running RPC Foo. Previously, we would've generated an extra method checkFooProgress, and if the proto has an actual RPC CheckFooProgress, the two names would've got into the conflict. With this change, the namer will detect the conflict, and the generated extra method will be called checkFooProgress1 (2, 3, etc.) The same will happen if the proto has methods Initialize, GetProjectId, etc. (which can conflict with the methods added by the generator).

To use the namer in the template, use {{ id.get("name") }} instead of just {{ name }}.

Note that only "naming" baseline (a special proto with a lot of naming conflicts) is changed. No existing API should be affected by this feature.

This feature will unblock generation of Ads TypeScript library. Cc: @aohren

Small note: I removed the part of the naming.proto that checks for TypeScript keywords conflicts, I'll get to that part later in a separate PR.

@alexander-fenster alexander-fenster requested a review from a team as a code owner August 28, 2020 00:06
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 28, 2020
@@ -112,21 +112,6 @@ service Naming {
body: "*"
};
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: the lines removed from the test proto correspond to a feature (reserved words) that I'm not going to cover soon.

return this.innerApiCalls.getProjectId(request, options, callback);
}
function(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: The lines removed from the test baseline correspond to a feature (reserved words) that I'm not going to cover soon.

@alexander-fenster alexander-fenster merged commit 420cbbc into master Aug 28, 2020
@alexander-fenster alexander-fenster deleted the naming-fix branch August 28, 2020 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants