You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 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
```Proto
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](https://github.com/fullstorydev/grpcui/files/13245072/server.txt)
## gRPC UI Output
```JSON
{
"nums": {
"abc": 3,
"xyz": 3
},
"answer": ""
}
```
## gRPCurl Output with `-emit-defaults=false`
```JSON
{
"nums": {
"abc": 3,
"xyz": 3
}
}
```
## Fix
- Added `emit-defaults` flag to the `cmd/grpcui.go` file.
- Set a global variable in `handlers.go` to accept value of
`emit-defaults` flag.
- The default value of this flag is `true`, to preserve existing
behavior
```bash
grpcui -h
...
-emit-defaults
Emit default values for JSON-encoded responses. (default true)
...
```
## gRPC UI Output After Fix with `-emit-defaults=false`
```JSON
{
"nums": {
"abc": 3,
"xyz": 3
}
}
```
---------
Co-authored-by: = <[email protected]>
0 commit comments