Skip to content

Commit

Permalink
grpc-ecosystem#1113 Fix broken parsing of camelCase oneof
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlaff authored and johanbrandhorst committed Jan 19, 2020
1 parent 3275ea6 commit f9b73e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 9 additions & 7 deletions runtime/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,16 @@ func fieldByProtoName(m reflect.Value, name string) (reflect.Value, *proto.Prope
props := proto.GetProperties(m.Type())

// look up field name in oneof map
if op, ok := props.OneofTypes[name]; ok {
v := reflect.New(op.Type.Elem())
field := m.Field(op.Field)
if !field.IsNil() {
return reflect.Value{}, nil, fmt.Errorf("field already set for %s oneof", props.Prop[op.Field].OrigName)
for _, op := range props.OneofTypes {
if name == op.Prop.OrigName || name == op.Prop.JSONName {
v := reflect.New(op.Type.Elem())
field := m.Field(op.Field)
if !field.IsNil() {
return reflect.Value{}, nil, fmt.Errorf("field already set for %s oneof", props.Prop[op.Field].OrigName)
}
field.Set(v)
return v.Elem().Field(0), op.Prop, nil
}
field.Set(v)
return v.Elem().Field(0), op.Prop, nil
}

for _, p := range props.Prop {
Expand Down
9 changes: 9 additions & 0 deletions runtime/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@ func TestPopulateParameters(t *testing.T) {
OneofValue: &proto3Message_OneofStringValue{"foobar"},
},
},
{
values: url.Values{
"oneofStringValue": {"foobar"},
},
filter: utilities.NewDoubleArray(nil),
want: &proto3Message{
OneofValue: &proto3Message_OneofStringValue{"foobar"},
},
},
{
values: url.Values{
"oneof_bool_value": {"true"},
Expand Down

0 comments on commit f9b73e0

Please sign in to comment.