fullstorydev / grpcui

An interactive web UI for gRPC, along the lines of postman
MIT License
5.24k stars 388 forks source link

Adding Emit Defaults Option #281

Closed James-Bartman closed 10 months ago

James-Bartman commented 1 year ago

Problem Statement

When using gRPC UI, I came across a scenario where I did not want default values emitted to the Response tab. While gRPCurl has an option to enable/disable emit-defaults, gRPC UI does not since the call it makes to gRPCurl hard-codes emit-defaults to true. Thus, there was an inconsistency between these two closely related tools.

Example Proto File

service Greeter {
   rpc SayHello (HelloRequest) returns (HelloReply);
}

message HelloRequest {
   string name = 1;
}

message TwoNums {
   int32 abc = 1;
   int32 xyz = 2;
}

message HelloReply {
   oneof HelloReplies {
      TwoNums nums = 1;
      int32 num = 2;
   }
   string answer = 3;
}

Sample Server Implementation - Written in Go

server.txt

gRPC UI Output

{
  "nums": {
    "abc": 3,
    "xyz": 3
  },
  "answer": ""
}

gRPCurl Output with -emit-defaults=false

{
  "nums": {
    "abc": 3,
    "xyz": 3
  }
}

Fix

grpcui -h
...
-emit-defaults
        Emit default values for JSON-encoded responses. (default true)
...

gRPC UI Output After Fix with -emit-defaults=false

{
  "nums": {
    "abc": 3,
    "xyz": 3
  }
}
James-Bartman commented 1 year ago

Just bumping this but not sure exactly who to notify. @dragonsinth @gpassini