Skip to content

Commit

Permalink
Accept bool in WithServerJSONCamelCaseNames
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwill committed Apr 19, 2021
1 parent eb2a1df commit b6a80d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestJSONSerializationCamelCase(t *testing.T) {
s := httptest.NewServer(
NewJSONSerializationServer(
&JSONSerializationService{},
twirp.WithServerJSONCamelCaseNames(),
twirp.WithServerJSONCamelCaseNames(true),
),
)
defer s.Close()
Expand Down
10 changes: 7 additions & 3 deletions server_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,13 @@ func WithServerJSONSkipDefaults(skipDefaults bool) ServerOption {
}

// WithServerJSONCamelCaseNames configures JSON serialization to use
// lowerCamelCase field names rather than proto snake_case names.
func WithServerJSONCamelCaseNames() ServerOption {
// lowerCameCase field names rather than the original proto field names.
// It is disabled by default, because JSON is commonly used for manual
// debugging. But sometimes converting to lowerCamelCase is needed
// to match the default canonical encoding on other proto-json parsers.
// See: https://developers.google.com/protocol-buffers/docs/proto3#json
func WithServerJSONCamelCaseNames(val bool) ServerOption {
return func(o *ServerOptions) {
o.JSONCamelCaseNames = true
o.JSONCamelCaseNames = val
}
}
2 changes: 1 addition & 1 deletion server_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestWithJSONSkipDefaults(t *testing.T) {
func TestWithServerJSONCamelCaseNames(t *testing.T) {
opts := &ServerOptions{}

WithServerJSONCamelCaseNames()(opts)
WithServerJSONCamelCaseNames(true)(opts)
if !opts.JSONCamelCaseNames {
t.Errorf("opts.JSONCamelCaseNames expected to be true, but it is false")
}
Expand Down

0 comments on commit b6a80d0

Please sign in to comment.