You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "spacewander (via GitHub)" <gi...@apache.org> on 2023/01/29 07:13:48 UTC

[GitHub] [apisix] spacewander commented on a diff in pull request #8731: fix: grpc-transcode plugin: fix map data population

spacewander commented on code in PR #8731:
URL: https://github.com/apache/apisix/pull/8731#discussion_r1089882085


##########
apisix/plugins/grpc-transcode/util.lua:
##########
@@ -164,15 +165,33 @@ function _M.map_message(field, default_values, request_table)
                 end
                 sub = sub_array
             else
-                sub, err = _M.map_message(field_type, default_values and default_values[name],
-                                          request_table[name])
+                if ty == "map" then
+                    local tbl
+                    for k, v in pairs(request_table[name]) do
+                        tbl, err = _M.map_message(field_type,
+                            default_values and default_values[name],
+                            request_table[name], k)
+                        if not sub then
+                            sub = {}
+                        end
+                        sub[k]= tbl[k]

Review Comment:
   ```suggestion
                           sub[k] = tbl[k]
   ```



##########
t/grpc_server_example/go.mod:
##########
@@ -3,6 +3,7 @@ module github.com/api7/grpc_server_example
 go 1.11
 
 require (
+	github.com/golang/protobuf v1.5.0 // indirect

Review Comment:
   Please run ` go mod tidy` to remove indirect mark



##########
apisix/plugins/grpc-transcode/util.lua:
##########
@@ -164,15 +165,33 @@ function _M.map_message(field, default_values, request_table)
                 end
                 sub = sub_array
             else
-                sub, err = _M.map_message(field_type, default_values and default_values[name],
-                                          request_table[name])
+                if ty == "map" then
+                    local tbl
+                    for k, v in pairs(request_table[name]) do
+                        tbl, err = _M.map_message(field_type,
+                            default_values and default_values[name],
+                            request_table[name], k)
+                        if not sub then
+                            sub = {}
+                        end
+                        sub[k]= tbl[k]

Review Comment:
   Let's check err before accessing tbl



##########
t/plugin/grpc-transcode-struct.t:
##########
@@ -0,0 +1,121 @@
+#

Review Comment:
   Could we move these tests under https://github.com/apache/apisix/blob/master/t/plugin/t/plugin/grpc-transcode3.t? This file is small and doesn't have special setup.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org