-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Support for map type in query string #535
Conversation
ca54f61
to
6e5fd3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a great thing to add to grpc-gateway. A few small tweaks and then I'm happy to merge this 😄
runtime/query.go
Outdated
@@ -84,6 +94,11 @@ func populateFieldValueFromPath(msg proto.Message, fieldPath []string, values [] | |||
case reflect.Struct: | |||
m = f | |||
continue | |||
case reflect.Map: | |||
if !isLast { | |||
return fmt.Errorf("unexpected map field in %s", strings.Join(fieldPath, ".")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate in this error message. As I understand it the conern here is that you could make the querystring ?foo[bar]
which doesn't have a value. Could you add a remark about what was expected and why this is an error condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to handle the case where an intermediate field in fieldPath
refers to a map.
i.e. obj.nested.map_field.foo
where map_field
is a map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you enhance the error message to reflect that intent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure no problem.
runtime/query_test.go
Outdated
"map_value12[key]": {"2.5"}, | ||
"map_value13[2.5]": {"value"}, | ||
"map_value14[key]": {"true"}, | ||
"map_value15[true]": {"value"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some examples where you populate multiple map values at the same time?
6e5fd3d
to
9c3146c
Compare
9c3146c
to
1abcd3a
Compare
Thanks for the feedback! I think my latest commit addresses your comments. |
Thanks for the new feature and thanks for contributing! |
Adds support for the map type in query strings. Filter strings take the form:
?map_field[key]=value
.Only maps with primitive keys and values are supported.
Closes #316