solnic / drops

🛠️ Tools for working with data effectively - data contracts using types, schemas, domain validation rules, type-safe casting, and more.
Other
257 stars 6 forks source link

13 support for lists #19

Closed solnic closed 1 year ago

solnic commented 1 year ago

This adds support for typed lists

defmodule TestContract do
  use Drops.Contract

  schema do
    %{
      required(:tags) => type(list: %{
        required(:name) => type(:string)
      })
    }
  end
end

TestContract.conform(%{tags: [%{name: "red"}, %{name: "green"}, %{name: "blue"}]})
# {:ok, %{tags: [%{name: "red"}, %{name: "green"}, %{name: "blue"}]}}

TestContract.conform(%{tags: [%{name: "red"}, %{name: 312}, %{name: "blue"}]})
# {:error, [error: [{:string?, [:tags, 1, :name], 312}]]}

Closes #13