From 98804b0b96567084c801bab855d0e1534fb0cae7 Mon Sep 17 00:00:00 2001 From: zhoujiexiong Date: Tue, 30 Jul 2024 13:06:03 +0800 Subject: [PATCH 1/2] chore(grpc-transcode): adjust the position of enums in pb_option_def --- apisix/plugins/grpc-transcode.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apisix/plugins/grpc-transcode.lua b/apisix/plugins/grpc-transcode.lua index a89008d39790..625018fb71fc 100644 --- a/apisix/plugins/grpc-transcode.lua +++ b/apisix/plugins/grpc-transcode.lua @@ -27,11 +27,11 @@ local plugin_name = "grpc-transcode" local pb_option_def = { { description = "enum as result", type = "string", - enum = {"int64_as_number", "int64_as_string", "int64_as_hexstring"}, + enum = {"enum_as_name", "enum_as_value"}, }, { description = "int64 as result", type = "string", - enum = {"enum_as_name", "enum_as_value"}, + enum = {"int64_as_number", "int64_as_string", "int64_as_hexstring"}, }, { description ="default values option", type = "string", From 148d10d2d3314ed414bdd5670d37cb0f854a17f6 Mon Sep 17 00:00:00 2001 From: zhoujiexiong Date: Wed, 31 Jul 2024 10:21:40 +0800 Subject: [PATCH 2/2] add test case: === TEST 14: pb_option - check the matchings between enum and category --- t/plugin/grpc-transcode3.t | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/t/plugin/grpc-transcode3.t b/t/plugin/grpc-transcode3.t index 0a8ddf54ded6..93a3d626766d 100644 --- a/t/plugin/grpc-transcode3.t +++ b/t/plugin/grpc-transcode3.t @@ -576,3 +576,46 @@ location /t { } --- response_body passed + + + +=== TEST 14: pb_option - check the matchings between enum and category +--- config + location /t { + content_by_lua_block { + local ngx_re_match = ngx.re.match + local plugin = require("apisix.plugins.grpc-transcode") + + local pb_option_def = plugin.schema.properties.pb_option.items.anyOf + + local patterns = { + [[^enum_as_.+$]], + [[^int64_as_.+$]], + [[^.+_default_.+$]], + [[^.+_hooks$]], + } + + local function check_pb_option_enum_category() + for i, category in ipairs(pb_option_def) do + for _, enum in ipairs(category.enum) do + if not ngx_re_match(enum, patterns[i], "jo") then + return ([[mismatch between enum("%s") and category("%s")]]):format( + enum, category.description) + end + end + end + end + + local err = check_pb_option_enum_category() + if err then + ngx.say(err) + return + end + + ngx.say("done") + } + } +--- request +GET /t +--- response_body +done