From 88d3499807a7b67658b503d27bc37cedba2286b0 Mon Sep 17 00:00:00 2001 From: Johnny Graettinger Date: Tue, 24 Sep 2024 09:22:12 -0500 Subject: [PATCH] grpc-gateway: emit default (zero-value) fields Some existing clients are not as nimble at distinguishing the explicit empty vs implicit empty cases. --- cmd/gazette/main.go | 2 +- mainboilerplate/runconsumer/run_consumer.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/gazette/main.go b/cmd/gazette/main.go index bc1ae2b1..2967abda 100644 --- a/cmd/gazette/main.go +++ b/cmd/gazette/main.go @@ -120,7 +120,7 @@ func (cmdServe) Execute(args []string) error { pb.RegisterJournalServer(srv.GRPCServer, pb.NewVerifiedJournalServer(service, verifier)) var mux *runtime.ServeMux = runtime.NewServeMux( - runtime.WithMarshalerOption(runtime.MIMEWildcard, new(gateway.JSONPb)), + runtime.WithMarshalerOption(runtime.MIMEWildcard, &gateway.JSONPb{EmitDefaults: true}), runtime.WithProtoErrorHandler(runtime.DefaultHTTPProtoErrorHandler), ) pb.RegisterJournalHandler(tasks.Context(), mux, srv.GRPCLoopback) diff --git a/mainboilerplate/runconsumer/run_consumer.go b/mainboilerplate/runconsumer/run_consumer.go index a8924741..7179d052 100644 --- a/mainboilerplate/runconsumer/run_consumer.go +++ b/mainboilerplate/runconsumer/run_consumer.go @@ -199,7 +199,7 @@ func (sc Cmd) Execute(args []string) error { pc.RegisterShardServer(srv.GRPCServer, pc.NewVerifiedShardServer(service, service.Verifier)) var mux *runtime.ServeMux = runtime.NewServeMux( - runtime.WithMarshalerOption(runtime.MIMEWildcard, new(gateway.JSONPb)), + runtime.WithMarshalerOption(runtime.MIMEWildcard, &gateway.JSONPb{EmitDefaults: true}), runtime.WithProtoErrorHandler(runtime.DefaultHTTPProtoErrorHandler), ) pc.RegisterShardHandler(tasks.Context(), mux, srv.GRPCLoopback)