AlinsRan commented on code in PR #12718:
URL: https://github.com/apache/apisix/pull/12718#discussion_r2508457735


##########
apisix/admin/standalone.lua:
##########
@@ -211,54 +333,44 @@ local function update(ctx)
         return core.response.exit(204)
     end
 
-    -- check input by jsonschema
+    local valid, error_msg = validate_configuration(req_body, false)
+    if not valid then
+        return core.response.exit(400, { error_msg = error_msg })
+    end
+
+    -- check input by jsonschema and build the final config
     local apisix_yaml = {}
 
     for key, conf_version_key in pairs(ALL_RESOURCE_KEYS) do
         local conf_version = config and config[conf_version_key] or 0
         local items = req_body[key]
         local new_conf_version = req_body[conf_version_key]
-        local resource = resources[key] or {}
-        if not new_conf_version then
-            new_conf_version = conf_version + 1
-        else
-            if type(new_conf_version) ~= "number" then
-                return core.response.exit(400, {
-                    error_msg = conf_version_key .. " must be a number",
-                })
-            end
+
+        if new_conf_version then
             if new_conf_version < conf_version then
                 return core.response.exit(400, {
                     error_msg = conf_version_key ..
                         " must be greater than or equal to (" .. conf_version 
.. ")",
                 })
             end
+        else
+            new_conf_version = conf_version + 1
         end
 
-
         apisix_yaml[conf_version_key] = new_conf_version
         if new_conf_version == conf_version then
             apisix_yaml[key] = config and config[key]
         elseif items and #items > 0 then
             apisix_yaml[key] = table_new(#items, 0)
-            local item_schema = resource.schema
-            local item_checker = resource.checker
             local id_set = {}
 
-            for index, item in ipairs(items) do
-                local item_temp = tbl_deepcopy(item)
-                local valid, err = check_conf(item_checker, item_schema, 
item_temp, key)
-                if not valid then
-                    local err_prefix = "invalid " .. key .. " at index " .. 
(index - 1) .. ", err: "
-                    local err_msg = type(err) == "table" and err.error_msg or 
err
-                    core.response.exit(400, { error_msg = err_prefix .. 
err_msg })
-                end
+            for _, item in ipairs(items) do
                 -- prevent updating resource with the same ID
                 -- (e.g., service ID or other resource IDs) in a single request
                 local duplicated, err = check_duplicate(item, key, id_set)

Review Comment:
   The logic of `check_deuplicate` exists twice, the first time in 
`validate_configuration`, and the second time is redundant.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to