Skip to content

Commit

Permalink
Merge pull request Kong#276 from Mashape/fix/273
Browse files Browse the repository at this point in the history
[fix/admin api] notify which subfields are required

Former-commit-id: 3f3860e5708cf47fa319c031f49ebf130e4d2129
  • Loading branch information
thibaultcha committed May 29, 2015
2 parents d7a0b43 + 9c18a35 commit c28c4d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions kong/dao/schemas_validation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/schemas_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c28c4d2

Please sign in to comment.