@@ -51,21 +51,28 @@ defmodule Norm.Spec.Selection do
5151 defp validate_selectors! ( [ _key | rest ] ) , do: validate_selectors! ( rest )
5252 defp validate_selectors! ( other ) , do: raise ArgumentError , "select expects a list of keys but received: #{ inspect other } "
5353
54- defp assert_spec! ( schema , key ) do
54+ defp assert_spec! ( % Schema { } = schema , key ) do
5555 case Schema . spec ( schema , key ) do
5656 nil -> raise SpecError , { :selection , key , schema }
5757 spec -> spec
5858 end
5959 end
60+ defp assert_spec! ( % __MODULE__ { } , _key ) do
61+ # In the future we might support this and allow users to overwrite internal
62+ # selections. But for now its safer to forbid this.
63+ raise ArgumentError , """
64+ Attempting to specify a selection on top of another selection is
65+ not allowed.
66+ """
67+ end
68+ defp assert_spec! ( other , _key ) do
69+ raise ArgumentError , "Expected a schema and got: #{ inspect other } "
70+ end
6071
6172 defimpl Norm.Conformer.Conformable do
6273 alias Norm.Conformer
6374 alias Norm.Conformer.Conformable
6475
65- # def conform(_, input, path) when not is_map(input) do
66- # {:error, [Conformer.error(path, input, "not a map")]}
67- # end
68-
6976 def conform ( % { required: required , schema: schema } , input , path ) do
7077 with { :ok , conformed } <- Conformable . conform ( schema , input , path ) do
7178 errors = ensure_keys ( required , conformed , path , [ ] )
0 commit comments