Skip to content

fix: allow proto3 optional fields in path parameters#6416

Merged
johanbrandhorst merged 2 commits intogrpc-ecosystem:mainfrom
susanachl:susanachl/option_fix
Mar 4, 2026
Merged

fix: allow proto3 optional fields in path parameters#6416
johanbrandhorst merged 2 commits intogrpc-ecosystem:mainfrom
susanachl:susanachl/option_fix

Conversation

@susanachl
Copy link
Copy Markdown
Contributor

References to other Issues or PRs

Fixes #6352

Motivation & Context

This PR removes the compiler restriction (originally introduced in #1951) that prevents proto3 optional fields from being mapped to HTTP path parameters.

Addressing the Routing Ambiguity Concern:
By removing this check, we decouple the Protobuf schema validation from the HTTP routing layer. If an optional field is mapped to a path parameter like /owners/{owner_name}/pets/, the structural requirement of the URL template remains intact.

If a client omits the optional field, resulting in an empty path segment (POST /v1/owners//pets/fido:feed), the underlying gRPC-Gateway HTTP router will naturally fail to match the template and return a 404 Not Found. This correctly shifts the responsibility of validating path completeness from the proto compiler to the HTTP router, which is the expected behavior for malformed requests.

Changes

  • Removed proto3_optional check in internal/descriptor/services.go.
  • Refactored TestOptionalProto3URLPathMappingError to TestOptionalProto3URLPathMappingSuccess in internal/descriptor/services_test.go.
  • Added an additional_binding to the Custom RPC in examples/internal/proto/examplepb/a_bit_of_everything.proto using an optional path parameter to prove end-to-end generation success.

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.

LGTM, thank you! I can't think of a reason this would break any existing users, and since this is something multiple users want, lets try it and see how it goes :).

@johanbrandhorst johanbrandhorst enabled auto-merge (squash) March 4, 2026 16:45
@johanbrandhorst
Copy link
Copy Markdown
Collaborator

Looks like you need to run the regenerate command, see CONTRIBUTING.md for instructions. Thanks!

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.

Allow optional fields in field path

2 participants