diff --git a/lib/dry/schema/dsl.rb b/lib/dry/schema/dsl.rb index e3b453bb..b7067405 100644 --- a/lib/dry/schema/dsl.rb +++ b/lib/dry/schema/dsl.rb @@ -437,7 +437,7 @@ def parent_filter_schemas # # @api private def key_validator - KeyValidator.new(key_map: key_map + parent_key_map) + KeyValidator.new(key_map: key_map) end # Build a key coercer diff --git a/spec/integration/schema/steps_spec.rb b/spec/integration/schema/steps_spec.rb index b06f34a4..67f6f7b9 100644 --- a/spec/integration/schema/steps_spec.rb +++ b/spec/integration/schema/steps_spec.rb @@ -204,4 +204,24 @@ }.to raise_error(ArgumentError, /oops/) end end + + context "with an inherited params" do + describe "core step key maps" do + it "copies key map from the parent and includes new keys from child" do + parent = Dry::Schema.Params do + config.validate_keys = true + + required(:name).filled(:string) + end + + child = Dry::Schema.Params(parent: parent) do + required(:email).filled(:string) + end + + %i[key_validator key_coercer].each do |step| + expect(child.steps[step].executor.key_map.map(&:name)).to eql(%w[name email]) + end + end + end + end end diff --git a/spec/integration/schema/unexpected_keys_spec.rb b/spec/integration/schema/unexpected_keys_spec.rb index cde1d683..6771539a 100644 --- a/spec/integration/schema/unexpected_keys_spec.rb +++ b/spec/integration/schema/unexpected_keys_spec.rb @@ -150,4 +150,21 @@ end end end + + context "with an inherited params" do + it "copies key map from the parent and includes new keys from child" do + parent = Dry::Schema.Params do + config.validate_keys = true + + required(:name).filled(:string) + end + + child = Dry::Schema.Params(parent: parent) do + required(:email).filled(:string) + end + + expect(child.(name: "Jane", email: "jane@doe.org", unexpected_key: "boo!").errors.to_h) + .to eql({unexpected_key: ["is not allowed"]}) + end + end end