diff --git a/kong/dao/schemas_validation.lua b/kong/dao/schemas_validation.lua index 082791bc68d..27d697ffd18 100644 --- a/kong/dao/schemas_validation.lua +++ b/kong/dao/schemas_validation.lua @@ -103,17 +103,17 @@ function _M.validate(t, schema, is_update) if sub_schema then -- Check for sub-schema defaults and required properties - for _, sub_field in pairs(sub_schema) do + for sub_field_k, sub_field in pairs(sub_schema) do if t[column] == nil then if sub_field.default then t[column] = {} elseif sub_field.required then -- only check required if field doesn't have a default - v.required = true + errors = utils.add_error(errors, column, column.."."..sub_field_k.." is required") end end end - if t[column] then + if t[column] and type(t[column]) == "table" then -- validating subschema local s_ok, s_errors = _M.validate(t[column], sub_schema, is_update) if not s_ok then diff --git a/spec/unit/schemas_spec.lua b/spec/unit/schemas_spec.lua index a9945d67ce7..2a4b932df06 100644 --- a/spec/unit/schemas_spec.lua +++ b/spec/unit/schemas_spec.lua @@ -428,7 +428,7 @@ describe("Schemas", function() local valid, err = validate(obj, schema) assert.truthy(err) assert.False(valid) - assert.are.same("value is required", err.value) + assert.are.same("value.some_property is required", err.value) end) end)