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

Wrong key validation when empty block #377

Open
patodevilla opened this issue Nov 5, 2021 · 0 comments
Open

Wrong key validation when empty block #377

patodevilla opened this issue Nov 5, 2021 · 0 comments

Comments

@patodevilla
Copy link

patodevilla commented Nov 5, 2021

Describe the bug

Upgraded from version 1.6.1 to 1.7.1 and detected error in my app's tests. Basically, when an empty block is passed, key validation is wrongly validated.

I consider the bug not to be common in most apps, I just happen to have an empty block in case we needed it in the future.

To Reproduce

schema = Dry::Schema.JSON do
  config.validate_keys = true

  required(:anyOf).array(:hash) do
    optional(:some_key)
  end
end

schema.({'anyOf' => []})
# =>  #<Dry::Schema::Result{:anyOf=>[]} errors={} path=[]>
schema = Dry::Schema.JSON do
  config.validate_keys = true

  required(:anyOf).array(:hash) do
  end
end

schema.({'anyOf' => []})
# => #<Dry::Schema::Result{:anyOf=>[]} errors={:anyOf=>["is not allowed"]} path=[]>

Expected behavior

anyOf key should be valid

My environment

  • Affects my production application: YES
  • Ruby version: 2.7.4
  • OS: macOS Big Sur 11.6 M1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant