This adds a basic support for coercion functions. The DSL allows you to define from which type you want to coerce and what should be the resulting type. Additional constraints for the input type are not added at this point, but it's as good starting point.
defmodule TestContract do
use Drops.Contract
schema do
%{
required(:code) => from(:integer) |> type(:string),
required(:price) => from(:string) |> type(:integer)
}
end
end
TestContract.conform(%{code: 12, price: "11"})
# {:ok, %{code: "12", price: 11}}
TestContract.conform(%{code: 12, price: 11})
# {:error, [error: {:string?, :price, 11}]}
This adds a basic support for coercion functions. The DSL allows you to define from which type you want to coerce and what should be the resulting type. Additional constraints for the input type are not added at this point, but it's as good starting point.