Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error messages for invalid nested data (via keys inside hash?) are not similarly nested #74

Closed
timriley opened this issue Mar 15, 2016 · 0 comments

Comments

@timriley
Copy link
Member

With a schema like this, with a single rule inside a single level of nesting:

schema = Dry::Validation.Schema do
  key(:meta) do
    hash? do
      key(:pages).required(:int?)
    end
  end
end

When I call it with invalid data, the error messages are not properly nested:

schema.(meta: {pages: "123"}).messages
# => {:meta=>["must be an integer"]}

FWIW, if I set the meta hash without any child keys, the error messages are properly nested:

schema.(meta: {}).messages
# => {:meta=>{:pages=>["is missing"]}}

This only seems to be a problem for keys inside a hash? block. If I use a nested schema instead:

schema = Dry::Validation.Schema do
  key(:meta).schema do
    key(:pages).required(:int?)
  end
end

Then the error messages come back properly:

schema.(meta: {pages: "123"}).messages
# => {:meta=>{:pages=>["must be an integer"]}}
@solnic solnic closed this as completed in f2fefde Mar 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant