kong icon indicating copy to clipboard operation
kong copied to clipboard

grpc-gateway does not translate proto to/from json as expected

Open alain-baxter opened this issue 4 months ago • 3 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Kong version ($ kong version)

3.10

Current Behavior

With an example Proto file like:

syntax = "proto3";

package example.v1;

import "google/protobuf/wrappers.proto";

enum RegionType {
  TYPE_1 = 0;
  TYPE_2 = 1;
}

message Region {
  RegionType type = 1;
  google.protobuf.StringValue code = 2;
}

message Summary {
  message More {
    int64 diff = 1;
  }

  message Same {}

  message NoneFound {}

  oneof state {
    More more = 1;
    Same same = 2;
    NoneFound none_found = 3;
  }
}

message Bucket {
  repeated string dates = 1;
  Summary summary = 2
}

message ExampleRequest {
  Region origin = 1;
  Region destination = 2;
}

message ExampleResponse {
  repeated Bucket buckets = 1;
}

service BucketDataService {
  rpc GetBuckets(ExampleRequest) returns (ExampleResponse) {
    option (google.api.http) = {
      post: "/buckets"
      body: "*"
    };
  };
}

We are experiencing two issues with how it's being translated to JSON by the grpc-gateway plugin.

  1. google.protobuf.StringValue is not getting treated as a string. So in the request the code portion was only accepted when it was formatted as
"code": {
  "value": "YOW"
}
  1. oneof seems to be producing some odd schema structure. So in the response the summary portion was returned formatted as
"summary": {
  "state": "same",
  "same": {}
}

Expected Behavior

For the two noted issues in current, we expected:

  1. google.protobuf.StringValue is treated as a string, and we could request with
"code": "YOW",
  1. oneof defined sub resources, so the response would have
"summary": {
  "state": {
    "same": {}
  }
}

Steps To Reproduce

This is a standard grpc-gateway config pattern.

  1. Mount the proto into the gateway workload
  2. Create a service for the grpc service
  3. Create a http route to the service, attach the grpc-gateway plugin to this route, and point the plugin to the location of the mounted proto file
  4. Send requests to the http route

Anything else?

We know there has been ongoing effort in https://github.com/Kong/kong/pull/8297 to bring the grpc-gateway up to speed on ProtoJSON standards, however there did not seem to be an issue linked to that work, so maybe this can collect all the issues related to the proto <-> JSON translation that exists, and hopefully get some progress as that effort has been ongoing for > 3 years without resolution.

alain-baxter avatar Aug 22 '25 20:08 alain-baxter

Could you give us the proper version number? like 3.9.1 or 3.10.0.1?

chronolaw avatar Aug 25 '25 07:08 chronolaw

$ kong version
Kong Enterprise 3.10.0.4

alain-baxter avatar Aug 25 '25 13:08 alain-baxter

If you are using enterprise version you could create a ticket for more help.

chronolaw avatar Sep 01 '25 02:09 chronolaw