Merge pull request #3965 from guggero/rest-api-falsey

rpcserver: instruct REST marshaler to emit default values
This commit is contained in:
Olaoluwa Osuntokun 2020-01-27 12:19:57 -08:00 committed by GitHub
commit 04c3998f4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -750,6 +750,17 @@ func (r *rpcServer) Start() error {
} }
} }
// The default JSON marshaler of the REST proxy only sets OrigName to
// true, which instructs it to use the same field names as specified in
// the proto file and not switch to camel case. What we also want is
// that the marshaler prints all values, even if they are falsey.
customMarshalerOption := proxy.WithMarshalerOption(
proxy.MIMEWildcard, &proxy.JSONPb{
OrigName: true,
EmitDefaults: true,
},
)
// Finally, start the REST proxy for our gRPC server above. We'll ensure // Finally, start the REST proxy for our gRPC server above. We'll ensure
// we direct LND to connect to its loopback address rather than a // we direct LND to connect to its loopback address rather than a
// wildcard to prevent certificate issues when accessing the proxy // wildcard to prevent certificate issues when accessing the proxy
@ -757,7 +768,7 @@ func (r *rpcServer) Start() error {
// //
// TODO(roasbeef): eventually also allow the sub-servers to themselves // TODO(roasbeef): eventually also allow the sub-servers to themselves
// have a REST proxy. // have a REST proxy.
mux := proxy.NewServeMux() mux := proxy.NewServeMux(customMarshalerOption)
err := lnrpc.RegisterLightningHandlerFromEndpoint( err := lnrpc.RegisterLightningHandlerFromEndpoint(
context.Background(), mux, r.restProxyDest, context.Background(), mux, r.restProxyDest,