Skip to content

fix(gengateway): use opaque chain for setting path params#6215

Merged
johanbrandhorst merged 9 commits intogrpc-ecosystem:mainfrom
kellen-miller:fix-opaqueapi-patch-enum
Jan 21, 2026
Merged

fix(gengateway): use opaque chain for setting path params#6215
johanbrandhorst merged 9 commits intogrpc-ecosystem:mainfrom
kellen-miller:fix-opaqueapi-patch-enum

Conversation

@kellen-miller
Copy link
Copy Markdown
Contributor

Summary

  • add FieldPath helpers that derive the proper getter/setter chains when the opaque API is enabled
  • switch the grpc-gateway templates to those helpers for all opaque path-parameter assignments
  • document the behavior with unit tests so future template tweaks keep the opaque contract intact

Testing

  • go test ./internal/descriptor
  • go test ./protoc-gen-grpc-gateway/internal/gengateway

@kellen-miller kellen-miller changed the title fix(gengateway): honor opaque setters fix(gengateway): honor opaque setters for patch path params Jan 7, 2026
@kellen-miller kellen-miller changed the title fix(gengateway): honor opaque setters for patch path params fix(gengateway): use opaque chain for patch path params Jan 7, 2026
@kellen-miller kellen-miller changed the title fix(gengateway): use opaque chain for patch path params fix(gengateway): use opaque chain for path params Jan 8, 2026
Copy link
Copy Markdown
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Thanks for this, could you please add an example that uses this logic to some of our test files, it if doesn't already have it? See internal/examples/proto.

Comment thread internal/descriptor/types.go Outdated
@kellen-miller kellen-miller force-pushed the fix-opaqueapi-patch-enum branch 3 times, most recently from b0b8e0d to 50a2e39 Compare January 12, 2026 16:03
@kellen-miller
Copy link
Copy Markdown
Contributor Author

@johanbrandhorst PR should be good to review now. Added an example rpc that the PR is fixing (somewhat contrived). The getter chains in the gateway file are what is changing:
protoReq.GetOrder().GetShippingAddress().SetAddressType(OpaqueAddress_OpaqueAddressType(e))

Copy link
Copy Markdown
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Great, thanks for the fix!

@johanbrandhorst
Copy link
Copy Markdown
Collaborator

Looks like you'll need to regenerate the protobuf files with that change again, if you're unsure, check CONTRIBUTING.md for the steps. Thanks!

@kellen-miller
Copy link
Copy Markdown
Contributor Author

@johanbrandhorst addressed the CI issues, do we want to commit the updated MODULE.bazel.lock file as well? I noticed it had a lot of changes on my local not related to me so omitted it from the commit.

@kellen-miller kellen-miller changed the title fix(gengateway): use opaque chain for path params fix(gengateway): use opaque chain for setting path params Jan 18, 2026
Copy link
Copy Markdown
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Unfortuantely another PR snuck in before yours so you'll need to regenerate the files again after rebasing on main 😅. Sorry for the inconvenience!

@johanbrandhorst
Copy link
Copy Markdown
Collaborator

@johanbrandhorst addressed the CI issues, do we want to commit the updated MODULE.bazel.lock file as well? I noticed it had a lot of changes on my local not related to me so omitted it from the commit.

Lets see what the generate or bazel jobs say. If they expect an update, we'll update it.

@johanbrandhorst
Copy link
Copy Markdown
Collaborator

Looks like bazel and generate are both happy, so once this is rebased and regenerated it's good to go!

[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
@kellen-miller kellen-miller force-pushed the fix-opaqueapi-patch-enum branch from 4f84f87 to 39715cb Compare January 20, 2026 17:33
@kellen-miller
Copy link
Copy Markdown
Contributor Author

@johanbrandhorst rebased and regenerated, hopefully good to go now!

@johanbrandhorst johanbrandhorst merged commit d40824a into grpc-ecosystem:main Jan 21, 2026
14 checks passed
@johanbrandhorst
Copy link
Copy Markdown
Collaborator

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants