You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's an inconsistency that leads to some unexpected behavior when using nested schemas. The problem is best described by the example below.
To Reproduce & Expected behavior
FriendSchema=Dry::Schema.Paramsdooptional(:nickname).filled(:string)endclassUserSchema < Dry::Validation::Contractparamsdooptional(:name)optional(:close_friends).maybe(:array,FriendSchema)optional(:friends).maybedoarray(FriendSchema)endendendUserSchema.new.call({name: "John",friends: []})# worksUserSchema.new.call({name: "John",close_friends: []})# expects to work but does notNoMethodError: undefinedmethod`key?' for []:Arrayfrom /Users/lenart/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/dry-logic-1.1.0/lib/dry/logic/predicates.rb:25:in `key?'
If filled(:string) is omitted from FriendSchema the error goes away but in that case, all params get through.
FriendSchema=Dry::Schema.Paramsdooptional(:nickname)end# UserSchema same as in above exampleUserSchema.new.call({name: "John",close_friends: [{any: 'value'}]})# expected {name: "John"}# actual {name: "John", close_friends: [{any: "value"}]}UserSchema.new.call({name: "John",friends: [{any: 'value'}]})# returns as expected {name: "John", friends: [{}]}
I'm not sure that the empty object is what I'd expect in the friends array.
The same syntax seems to work fine when dealing with hashes (instead of arrays).
I assigned it to 2.0.0 because all DSL inconsistencies will be easier to address after a couple of improvements/refactorings are done, and they are scheduled for 2.0.0.
Describe the bug
There's an inconsistency that leads to some unexpected behavior when using nested schemas. The problem is best described by the example below.
To Reproduce & Expected behavior
If
filled(:string)
is omitted fromFriendSchema
the error goes away but in that case, all params get through.I'm not sure that the empty object is what I'd expect in the
friends
array.The same syntax seems to work fine when dealing with hashes (instead of arrays).
My environment
other related gems in
Gemfile.lock
The text was updated successfully, but these errors were encountered: