Closed andreaseger closed 8 years ago
Yes this is the new behavior. We can introduce a symbolized-strict version too although I'm not sure if that's a good idea. If you need to coerce input it's better/safer to use dry-validation. Could you tell me what your use-case is?
so the schema
and the symbolized
hash schema only do coersion but no type checking? Personally can't see a use_case right now where I would want that but OK.
An example where we used this was for validating and coercion (and symbolizing) of a nested hash in a request body. But I guess we could migrate this to dry-validation although we liked that we wouldn't need to symbolize known keys and remove unknown keys in the input ourself. ( unknown set of string-keys in -> known set of symbolized keys out + everything is is the type we want it to be )
An example where we used this was for validating and coercion (and symbolizing) of a nested hash in a request body.
dry-types is not a validation library. type-checking raises exceptions and it should be used in places where you do not expect invalid data.
we liked that we wouldn't need to symbolize known keys and remove unknown keys in the input ourself.
dry-validation rejects unknown keys automatically for you, it only cares about defined keys in a validation schema
unknown set of string-keys in -> known set of symbolized keys out + everything is is the type we want it to be
That's how dry-v works:
Dry::Validation.Form { required(:foo).filled(:str?) }.call(
"oops" => "dooh", "foo" => "hello", "such" => "unexpected"
)
=> #<Dry::Validation::Result output={:foo=>"hello"} messages={}>
I realize there are lots of moving parts in this gem right now and the documentation here is somewhat outdated. But I wonder why the type checking behaviour of the symbolized hash schema changed completely and won't do any type-checking at all now.
Here is how it behaved in
v0.7.2
(had to lock dry-logic to 0.2.3 because of some internal changes)As expected the second hash fails because the name isn't a string
using dry-types
v0.8.0
I see the followingWhat I see now is that the coersion was done but the strict type check was skipped or ignored.
Is this intended behaviour?