drops
drops copied to clipboard
schema(atomize: true) doesn't accept atoms
The schema(atomize: true) does not accept atoms. Is this a bug?
defmodule Contract do
use Drops.Contract
schema(atomize: true) do
%{
required(:name) => string()
}
end
end
Contract.conform(%{"name" => "John Doe"})
# => {:ok, %{name: "John Doe"}}
Contract.conform(%{name: "John Doe"})
# {:error,
# [
# %Drops.Validator.Messages.Error.Type{
# path: [:name],
# text: "key must be present",
# meta: [predicate: :has_key?, args: [[:name]]]
# }
# ]}
Thanks for reporting this. A pragmatic way would be to accept atoms too (that's how it works in dry-schema that this lib is inspired by) but I'd also probably consider adding a strict mode where the current behavior would be maintained. WDYT?
Accepting atoms seems a way to go, but there was a reason the library was designed as it is. I noticed you've added processor steps to dry-schema, this might be the solution. Still thinking.
@ndan yes I think it's just a very pragmatic thing to do