Skip to content

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

@alain-baxter

Description

@alain-baxter

Is there an existing issue for this?

  • 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 #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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions