Skip to content

Commit

Permalink
chore(grpc-transcode): adjust the position of enums in pb_option_def (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoujiexiong authored Aug 5, 2024
1 parent 0603726 commit e746746
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apisix/plugins/grpc-transcode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions t/plugin/grpc-transcode3.t
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e746746

Please sign in to comment.