You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by mo...@apache.org on 2023/05/25 14:44:57 UTC

[apisix] branch master updated: feat: add id to global_rules schema (#9517)

This is an automated email from the ASF dual-hosted git repository.

monkeydluffy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 216e54dd9 feat: add id to global_rules schema (#9517)
216e54dd9 is described below

commit 216e54dd99fb2eef7ebf681b78cce7d835b4bb9d
Author: 青鱼 <41...@qq.com>
AuthorDate: Thu May 25 22:44:46 2023 +0800

    feat: add id to global_rules schema (#9517)
---
 apisix/schema_def.lua |  2 +-
 t/core/schema_def.t   | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua
index 3ad4ebc25..f1d4d97ef 100644
--- a/apisix/schema_def.lua
+++ b/apisix/schema_def.lua
@@ -836,7 +836,7 @@ _M.global_rule = {
         create_time = timestamp_def,
         update_time = timestamp_def
     },
-    required = {"plugins"},
+    required = {"id", "plugins"},
 }
 
 
diff --git a/t/core/schema_def.t b/t/core/schema_def.t
index 0afee9c9d..b6a7bba05 100644
--- a/t/core/schema_def.t
+++ b/t/core/schema_def.t
@@ -82,3 +82,60 @@ __DATA__
     }
 --- response_body
 passed
+
+
+
+=== TEST 2: Missing required fields of global_rule.
+--- config
+    location /t {
+        content_by_lua_block {
+            local schema_def = require("apisix.schema_def")
+            local core = require("apisix.core")
+
+            local cases = {
+                {},
+                { id = "ADfwefq12D9s" },
+                { id = 1 },
+                {
+                    plugins = {
+                        foo = "bar",
+                    },
+                },
+            }
+            for _, c in ipairs(cases) do
+                local ok, err = core.schema.check(schema_def.global_rule, c)
+                assert(not ok)
+                assert(err ~= nil)
+                ngx.say("ok: ", ok, " err: ", err)
+            end
+        }
+    }
+--- request
+GET /t
+--- response_body eval
+qr/ok: false err: property "(id|plugins)" is required/
+
+
+
+=== TEST 3: Sanity check with minimal valid configuration.
+--- config
+    location /t {
+        content_by_lua_block {
+            local schema_def = require("apisix.schema_def")
+            local core = require("apisix.core")
+
+            local case = {
+                id = 1,
+                plugins = {},
+            }
+
+            local ok, err = core.schema.check(schema_def.global_rule, case)
+            assert(ok)
+            assert(err == nil)
+            ngx.say("passed")
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed