From 4885da9e5e593ecb62cf1b42a00635006fa05c95 Mon Sep 17 00:00:00 2001 From: Yixin Guo Date: Wed, 6 Aug 2025 13:59:58 -0500 Subject: [PATCH] fix(grpc): Fix error "proto3 disallow 'optional' label" When grpc-gateway plugin loads a proto3 proto file with optional labeled fields, it will throw an error "proto3 disallow 'optional' label". This fixes the issue by enabling proto3_optional in protoc. --- .../unreleased/kong/fix-missing-grpc-optional-support.yml | 3 +++ kong/tools/grpc.lua | 1 + spec/fixtures/grpc/targetservice.proto | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/kong/fix-missing-grpc-optional-support.yml diff --git a/changelog/unreleased/kong/fix-missing-grpc-optional-support.yml b/changelog/unreleased/kong/fix-missing-grpc-optional-support.yml new file mode 100644 index 00000000000..f0f43e80f6d --- /dev/null +++ b/changelog/unreleased/kong/fix-missing-grpc-optional-support.yml @@ -0,0 +1,3 @@ +message: Fixed an issue where gRPC plugins lack support for "optional". +scope: Plugin +type: bugfix \ No newline at end of file diff --git a/kong/tools/grpc.lua b/kong/tools/grpc.lua index a7d62f01b8f..31b0bb6ab69 100644 --- a/kong/tools/grpc.lua +++ b/kong/tools/grpc.lua @@ -77,6 +77,7 @@ function _M.new() protoc_instance:addpath(v) end protoc_instance.include_imports = true + protoc_instance.proto3_optional = true return setmetatable({ protoc_instance = protoc_instance, diff --git a/spec/fixtures/grpc/targetservice.proto b/spec/fixtures/grpc/targetservice.proto index e2f887fecce..59941114841 100644 --- a/spec/fixtures/grpc/targetservice.proto +++ b/spec/fixtures/grpc/targetservice.proto @@ -56,7 +56,7 @@ service Bouncer { message HelloRequest { string greeting = 1; - bool boolean_test = 2; + optional bool boolean_test = 2; } message HelloResponse {