Copilot commented on code in PR #12391:
URL: https://github.com/apache/apisix/pull/12391#discussion_r2218658771


##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -23,6 +23,44 @@ local string = string
 local ngx_decode_base64 = ngx.decode_base64
 local ipairs = ipairs
 local pcall  = pcall
+local type          = type
+local pairs         = pairs
+local setmetatable  = setmetatable
+
+pb.option "decode_default_array"
+local repeated_label = 3
+
+local function fetch_proto_array_names(proto_obj)
+    local names = {}
+    if type(proto_obj) == "table" then
+        for k,v in pairs(proto_obj) do
+            if type(v) == "table" then
+                local sub_names = fetch_proto_array_names(v)
+                for sub_name,_ in pairs (sub_names ) do
+                    names[sub_name]=1
+                end
+            end
+        end
+        if proto_obj["label"] == repeated_label then
+            names[proto_obj["name"]]=1

Review Comment:
   [nitpick] Missing spaces around assignment operator. Should be 
'names[proto_obj["name"]] = 1' for consistency.
   ```suggestion
               names[proto_obj["name"]] = 1
   ```



##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -23,6 +23,44 @@ local string = string
 local ngx_decode_base64 = ngx.decode_base64
 local ipairs = ipairs
 local pcall  = pcall
+local type          = type
+local pairs         = pairs
+local setmetatable  = setmetatable
+
+pb.option "decode_default_array"
+local repeated_label = 3
+
+local function fetch_proto_array_names(proto_obj)
+    local names = {}
+    if type(proto_obj) == "table" then
+        for k,v in pairs(proto_obj) do
+            if type(v) == "table" then
+                local sub_names = fetch_proto_array_names(v)
+                for sub_name,_ in pairs (sub_names ) do

Review Comment:
   Extra spaces around parentheses. Should be 'pairs(sub_names)' instead of 
'pairs (sub_names )'.
   ```suggestion
                   for sub_name,_ in pairs(sub_names) do
   ```



##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -23,6 +23,44 @@ local string = string
 local ngx_decode_base64 = ngx.decode_base64
 local ipairs = ipairs
 local pcall  = pcall
+local type          = type
+local pairs         = pairs
+local setmetatable  = setmetatable
+
+pb.option "decode_default_array"
+local repeated_label = 3
+
+local function fetch_proto_array_names(proto_obj)
+    local names = {}
+    if type(proto_obj) == "table" then
+        for k,v in pairs(proto_obj) do
+            if type(v) == "table" then
+                local sub_names = fetch_proto_array_names(v)
+                for sub_name,_ in pairs (sub_names ) do
+                    names[sub_name]=1

Review Comment:
   [nitpick] Missing spaces around assignment operator. Should be 
'names[sub_name] = 1' for consistency with line 45.
   ```suggestion
                       names[sub_name] = 1
   ```



##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -23,6 +23,44 @@ local string = string
 local ngx_decode_base64 = ngx.decode_base64
 local ipairs = ipairs
 local pcall  = pcall
+local type          = type
+local pairs         = pairs
+local setmetatable  = setmetatable
+
+pb.option "decode_default_array"
+local repeated_label = 3
+
+local function fetch_proto_array_names(proto_obj)
+    local names = {}
+    if type(proto_obj) == "table" then
+        for k,v in pairs(proto_obj) do
+            if type(v) == "table" then
+                local sub_names = fetch_proto_array_names(v)
+                for sub_name,_ in pairs (sub_names ) do
+                    names[sub_name]=1
+                end
+            end
+        end
+        if proto_obj["label"] == repeated_label then
+            names[proto_obj["name"]]=1
+        end
+    end
+    return names
+end
+
+local function set_default_array(tab, array_names)
+    if type(tab) ~= "table" then
+        return false
+    end
+    for k, v in pairs(tab) do
+        if type(v) == "table" then
+            if array_names[k] == 1 then
+                setmetatable(v,core.json.array_mt)

Review Comment:
   [nitpick] Missing space after comma. Should be 'setmetatable(v, 
core.json.array_mt)' for consistency with Lua style conventions.
   ```suggestion
                   setmetatable(v, core.json.array_mt)
   ```



##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -23,6 +23,44 @@ local string = string
 local ngx_decode_base64 = ngx.decode_base64
 local ipairs = ipairs
 local pcall  = pcall
+local type          = type
+local pairs         = pairs
+local setmetatable  = setmetatable
+
+pb.option "decode_default_array"
+local repeated_label = 3
+
+local function fetch_proto_array_names(proto_obj)
+    local names = {}
+    if type(proto_obj) == "table" then
+        for k,v in pairs(proto_obj) do
+            if type(v) == "table" then
+                local sub_names = fetch_proto_array_names(v)
+                for sub_name,_ in pairs (sub_names ) do
+                    names[sub_name]=1
+                end
+            end
+        end
+        if proto_obj["label"] == repeated_label then
+            names[proto_obj["name"]]=1
+        end
+    end
+    return names
+end
+
+local function set_default_array(tab, array_names)
+    if type(tab) ~= "table" then
+        return false
+    end
+    for k, v in pairs(tab) do
+        if type(v) == "table" then
+            if array_names[k] == 1 then
+                setmetatable(v,core.json.array_mt)
+            end
+            set_default_array(v,array_names)

Review Comment:
   [nitpick] Missing space after comma. Should be 'set_default_array(v, 
array_names)' for consistency with Lua style conventions.
   ```suggestion
               set_default_array(v, array_names)
   ```



##########
apisix/plugins/grpc-transcode/response.lua:
##########
@@ -132,6 +170,9 @@ return function(ctx, proto, service, method, pb_option, 
show_status_in_body, sta
         return err_msg
     end
 
+    local array_names = fetch_proto_array_names( proto )

Review Comment:
   [nitpick] Extra spaces around function parameter. Should be 
'fetch_proto_array_names(proto)' instead of 'fetch_proto_array_names( proto )'.
   ```suggestion
       local array_names = fetch_proto_array_names(proto)
   ```



-- 
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-unsubscr...@apisix.apache.org

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

Reply via email to