Skip to content

Commit

Permalink
add mux option for application/json (#4976)
Browse files Browse the repository at this point in the history
* add mux option for application/json

Signed-off-by: Yee Hing Tong <[email protected]>

* Emit unpopulated and default values

Signed-off-by: Eduardo Apolinario <[email protected]>

* Add comment

Signed-off-by: Eduardo Apolinario <[email protected]>

---------

Signed-off-by: Yee Hing Tong <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
  • Loading branch information
wild-endeavor and eapolinario authored Feb 28, 2024
1 parent 971c5ad commit e1d5a7a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions flyteadmin/pkg/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"fmt"
"google.golang.org/protobuf/encoding/protojson"
"net"
"net/http"
"strings"
Expand Down Expand Up @@ -201,6 +202,19 @@ func newHTTPServer(ctx context.Context, pluginRegistry *plugins.Registry, cfg *c
var gwmuxOptions = make([]runtime.ServeMuxOption, 0)
// This option means that http requests are served with protobufs, instead of json. We always want this.
gwmuxOptions = append(gwmuxOptions, runtime.WithMarshalerOption("application/octet-stream", &runtime.ProtoMarshaller{}))
// grpc-gateway v2 switched the marshaller used to encode JSON messages in 2.5.0. This changed the
// default encoding from snake_case (the v1 behavior) to lowerCamelCase, which is the case recommended
// by protobuf. However the protobuf docs do mention that JSON printers may provide a way to use
// the proto names as field names instead. This option in grpc-gateway v2 does just that,
// by setting a custom marshaler. We are enabling this narrowly however, by applying it only for
// the application/json content type.
gwmuxOptions = append(gwmuxOptions, runtime.WithMarshalerOption("application/json", &runtime.JSONPb{
MarshalOptions: protojson.MarshalOptions{
UseProtoNames: true,
EmitUnpopulated: true,
EmitDefaultValues: true,
},
}))

// This option sets subject in the user info response
gwmuxOptions = append(gwmuxOptions, runtime.WithForwardResponseOption(auth.GetUserInfoForwardResponseHandler()))
Expand Down

0 comments on commit e1d5a7a

Please sign in to comment.