diff --git a/lib/speck/validation_metadata/attribute.ex b/lib/speck/validation_metadata/attribute.ex index 8de4783..34c9a48 100644 --- a/lib/speck/validation_metadata/attribute.ex +++ b/lib/speck/validation_metadata/attribute.ex @@ -43,7 +43,7 @@ defmodule Speck.ValidationMetadata.Attribute do defp merge(nil = _params, [attribute | path], value, strategy) when not is_integer(attribute) do - %{attribute => merge(%{}, path, value, strategy)} + %{attribute => merge(nil, path, value, strategy)} end defp merge(params, [path], value, strategy) when is_map(params) do diff --git a/test/validation_metadata/attribute_test.exs b/test/validation_metadata/attribute_test.exs index e652577..53513d1 100644 --- a/test/validation_metadata/attribute_test.exs +++ b/test/validation_metadata/attribute_test.exs @@ -12,6 +12,26 @@ defmodule Speck.ValidationMetadata.Attribute.Test do %{"state" => %{"reported" => %{"serial" => "sn1234"}}} end + test "merge nested lists" do + attributes = [ + {["state", "reported", "a", 0, "b", 0, "c", 0, "d", 0, "id"], :unknown, 1001}, + {["state", "reported", "a", 1, "b", 0, "c", 0, "d", 0, "id"], :unknown, 1002}, + ] + + params = %{state: %{reported: %{}}} + + assert Attribute.merge(attributes, params) == %{ + "state" => %{ + "reported" => %{ + "a" => [ + %{"b" => [%{"c" => [%{"d" => [%{"id" => 1001}]}]}]}, + %{"b" => [%{"c" => [%{"d" => [%{"id" => 1002}]}]}]}, + ] + } + } + } + end + describe "merge strategy" do test "attribute priority" do params = %{"name" => "Test Device"}