dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
425 stars 109 forks source link

Key map contains duplicates on inheritance #372

Closed pyromaniac closed 8 months ago

pyromaniac commented 3 years ago

Describe the bug

When one schema is inherited from another one and redefines some fields, those fields got duplicated in the schema's key_map.

To Reproduce

class Foo < Dry::Schema::Params
  define do
    required(:foo).filled(:integer)
  end
end

class Bar < Foo
  define do
    required(:foo).filled(:string)
  end
end

Foo.new.key_map
#=> #<Dry::Schema::KeyMap["foo"]>
Bar.new.key_map
#=> #<Dry::Schema::KeyMap["foo", "foo"]>

Expected behavior

I would expect the exact list of schema keys in the keymap.

pyromaniac commented 3 years ago

@solnic, @flash-gordon I can even work on the PR fixing this. I just need to know your opinion, folks. Does it look like a bug to you or an intended behavior?

flash-gordon commented 3 years ago

@pyromaniac 💯 that wasn't planned to work like this :)

solnic commented 2 years ago

This was finally fixed in 1.10.5

pyromaniac commented 8 months ago

Thank you so much!