Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1113 Fix broken parsing of camelCase oneof #1114

Merged
merged 1 commit into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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