drops icon indicating copy to clipboard operation
drops copied to clipboard

schema(atomize: true) doesn't accept atoms

Open ndan opened this issue 1 year ago • 3 comments

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]]]
#    }
#  ]}

ndan avatar Jun 08 '24 15:06 ndan

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?

solnic avatar Jun 09 '24 05:06 solnic

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 avatar Jun 11 '24 16:06 ndan

@ndan yes I think it's just a very pragmatic thing to do

solnic avatar Jun 17 '24 06:06 solnic