Fix opaque missing imports casing#6304
Merged
johanbrandhorst merged 19 commits intogrpc-ecosystem:mainfrom Feb 2, 2026
Merged
Conversation
[WHY] Opaque-enabled protos expose nested fields only through getter/setter chains, so generated Setkey.* calls failed to compile yet path params remained unset. [WHAT] Added FieldPath helpers to build setter chains, swapped template setter sites to the helper, and codified the behavior with unit tests. [HOW] Build the accessor expression once from the descriptor so every opaque path-param assignment reuses it. [TEST] go test ./internal/descriptor; go test ./protoc-gen-grpc-gateway/internal/gengateway [RISK] low; changes affect only opaque path-param generation paths. [RAG] finxact_engineering_domain_customerv1poc_proto::module::buf|1.30,finxact_engineering_domain_customerv1poc_proto::module::finxact_type|1.59,finxact_engineering_domain_customerv1poc_gen_go::repo_overview|1.70
[WHY] Prevent regressions for the nested enum path-param case that triggered the bug. [WHAT] Add a generator test that synthesizes a proto3 file with an opaque nested enum binding and asserts the emitted setter chain. [HOW] Load the fake file into the descriptor registry so LookupEnum succeeds and search for the expected SetKind expression. [TEST] go test ./protoc-gen-grpc-gateway/internal/gengateway [RISK] none; test-only change [RAG] finxact_engineering_domain_customerv1poc_proto::module::buf|1.30,finxact_engineering_domain_customerv1poc_proto::module::finxact_type|1.59,finxact_engineering_domain_customerv1poc_gen_go::repo_overview|1.70
[WHY] The opaque setter bug isn’t limited to enums or PATCH bindings, so tests should cover both scalar and enum parameters across HTTP methods. [WHAT] Simplified the generator test to synthesize a proto with top-level path params and assert the opaque setter is emitted for GET (string) and PATCH (enum). [HOW] Build descriptors directly, cross-link them once, and verify the generated code contains the expected setter expression for each case. [TEST] go test ./protoc-gen-grpc-gateway/internal/gengateway [RISK] none; test-only change [RAG] finxact_engineering_domain_customerv1poc_proto::module::buf|1.30,finxact_engineering_domain_customerv1poc_proto::module::finxact_type|1.59,finxact_engineering_domain_customerv1poc_gen_go::repo_overview|1.70
[WHY] Opaque handlers were missing imports for nested body types and snake_case messages/enums produced invalid Go identifiers, causing broken builds when `--use_opaque_api` was enabled. [WHAT] Camel-case message/enum GoType helpers, register body-field packages during generation, and add example protos under `examples/internal/proto/examplepb` (opaque import + snake-case service/RPC names) and `examples/internal/proto/sub` (snake-case type) so `go test ./...` guards the regressions without extra generator-only tests. [HOW] Relocated the opaque example, regenerated it against the opaque API, extended the gateway generator to track external body packages, and leaned on the compiled examples instead of bespoke generator tests. [TEST] go test ./... [RISK] Low; scoped to generators/examples. Fixes grpc-ecosystem#6276, grpc-ecosystem#6277
…update message references - Introduced `OpaquePatchProductNameRequest` and `OpaquePatchProductNameResponse` types to the example proto. - Registered new request/response types in the services and updated references to message indices accordingly.
This commit deletes the outdated `examplepb/BUILD.bazel` file and eliminates unused proto and Bazel rule definitions. It also updates dependencies in `examplepb_opaque_proto` and `examplepb_opaque_go_proto` to include a missing reference to `sub_proto`, improving build correctness and simplifying the overall setup.
…ts-casing # Conflicts: # examples/internal/proto/examplepb/opaque.pb.go # examples/internal/proto/examplepb/opaque.pb.gw.go # examples/internal/proto/examplepb/opaque.proto # examples/internal/proto/examplepb/opaque.swagger.json # examples/internal/proto/examplepb/opaque_grpc.pb.go
[WHY] Non-opaque builds started failing with unused imports after the opaque body fix because we always pulled nested body packages, even when the generated code never referenced them. [WHAT] Only add body-field imports when --use_opaque_api is enabled, add an OpaqueEchoNote example under examplepb/opaque.proto that exercises cross-package opaque bodies, and regenerate the example artifacts. [HOW] Gated addBodyFieldImports, created a registry-backed unit test to cover both modes, and regenerated the opaque example outputs with the latest plugin. [TEST] go test ./... [RISK] Low; generator change scoped to opaque mode plus example updates.
Collaborator
|
Thanks a lot for the quick fix. @ryanriccio1 could you please try out this PR in your environment and confirm if it fixes the issue you were having? You should be able to install it by cloning the branch off @kellen-miller's fork and running |
|
@kellen-miller @johanbrandhorst Just pulled it and it looks good on my end! |
johanbrandhorst
approved these changes
Feb 2, 2026
Collaborator
|
This is why I love open source, thanks all :) |
This was referenced Apr 23, 2026
fix(deps): vuln minor upgrades — 11 packages (minor: 7 · patch: 4) [server]
DataDog/temporalio-ui#27
Closed
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
References to other Issues or PRs
Post Revert changes
After the revert #6299 due to #6294, I added a gate to make sure that the new
addBodyFieldImportsfunction only executes if the opaque api is being used.My camel_case_service should have caught that except it imported an enum from the sub message, which caused the sub message import to be used in the gateway file due to
runtime.Enumusing the type from the sub message. Sorry for the miss on that @ryanriccio1 @johanbrandhorst.Have you read the Contributing Guidelines?
Yes
Brief description of what is fixed or changed
--use_opaque_api) import the modulesthey instantiate.
descriptor.Message.GoType/Enum.GoType, ensuring proto names such asCreate_bookresolve to valid Go identifiers.examples/internal/proto/examplepb(opaque import with snake_case service/RPC names) andexamples/internal/proto/sub(snake-case messages) sogo test ./...guards both regressions without generator-onlyunit tests.
Other comments
go build ./...go test ./...