fix: use service name const instead of string literal in generated clients#16
Merged
iainmcgin merged 3 commits intoanthropics:mainfrom Apr 2, 2026
Merged
Conversation
…ients The codegen already emits a `*_SERVICE_NAME` const for each service, and the server-side router uses it. However, generated client methods repeated the fully-qualified service name as a string literal. This changes `generate_client_method` to accept the const ident and emit it in all four call sites (unary, server-stream, client-stream, bidi), improving consistency and making rename-refactors easier. Closes anthropics#9 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Collaborator
|
Thanks for the fix! I'll push the formatting fix onto your branch and merge. |
iainmcgin
approved these changes
Apr 2, 2026
Collaborator
iainmcgin
left a comment
There was a problem hiding this comment.
LGTM. Service-name const reference brings client emission into structural symmetry with the server-side dispatcher (which already uses the same const at 4 sites). Pushed an rustfmt fix to wrap the call.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses #9 — the codegen emits a
*_SERVICE_NAMEconst for each service, but generated client methods were repeating the fully-qualified name as a string literal instead of referencing the const.call_unary,call_server_stream,call_client_stream,call_bidi_stream) were using the fully-qualified service name as a string literal, even though the codegen already emits a*_SERVICE_NAMEconst at the top of each generated file.strip_prefix("service.name/")calls use a trailing-slash form and stay as-is (as noted in the issue).Problem (from #9)
Fix
Changed
generate_client_methodto accept the constIdentand emit it at all four call sites:Changes
connectrpc-codegen/src/codegen.rs:Identtoproc_macro2importgenerate_client_methodnow takesservice_name_const: &Ident+full_service_name: &str(kept for doc strings)call_unary,call_server_stream,call_client_stream,call_bidi_stream) emit the const ident instead of the string literalType safety
call_unaryetc. expectservice: &strpub const *_SERVICE_NAME: &str = "..."→ coerces to&str✓Test plan
cargo check --package connectrpc-codegen— compiles cleanlycargo test --package connectrpc-codegen— 10 tests passedbuf generateto verify generated output uses the const (requires buf CLI + protoc)Closes #9
🤖 Generated with Claude Code