This is an automated email from the ASF dual-hosted git repository. alinsran pushed a commit to branch revolyssup/standalone-validate in repository https://gitbox.apache.org/repos/asf/apisix.git
commit 84631ce5103e192ec6980fd32ca989fb45a1cdd5 Author: AlinsRan <[email protected]> AuthorDate: Thu Nov 20 10:33:33 2025 +0800 update conmments --- apisix/admin/standalone.lua | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/apisix/admin/standalone.lua b/apisix/admin/standalone.lua index f55a90ac0..2787d79da 100644 --- a/apisix/admin/standalone.lua +++ b/apisix/admin/standalone.lua @@ -170,20 +170,13 @@ local function validate_configuration(req_body, collect_all_errors) -- Validate conf_version_key if present local new_conf_version = req_body[conf_version_key] if new_conf_version and type(new_conf_version) ~= "number" then - local error_msg - if collect_all_errors then - error_msg = conf_version_key .. " must be a number, got " .. type(new_conf_version) - else - error_msg = conf_version_key .. " must be a number" - end - if not collect_all_errors then - return false, error_msg + return false, config_version_key .. " must be a number" end validation_results.valid = false table_insert(validation_results.errors, { resource_type = key, - error = error_msg + error = conf_version_key .. " must be a number, got " .. type(new_conf_version) }) end @@ -264,19 +257,18 @@ local function validate(ctx) end local valid, validation_results = validate_configuration(data, true) - - if valid then - return core.response.exit(200, { - message = "Configuration is valid", - valid = true - }) - else + if not valid then return core.response.exit(400, { error_msg = "Configuration validation failed", valid = false, errors = validation_results.errors }) end + + return core.response.exit(200, { + message = "Configuration is valid", + valid = true + }) end local function update(ctx) @@ -316,8 +308,7 @@ local function update(ctx) req_body = data local config, err = get_config() - if not config then - if err ~= NOT_FOUND_ERR then + if err and err ~= NOT_FOUND_ERR then core.log.error("failed to get config from shared dict: ", err) return core.response.exit(500, { error_msg = "failed to get config from shared dict: " .. err
