-
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Hi, it looks like there might be an issue with validating nested lists.
Repro:
defmodule NestedListStruct do
use GuardedStruct
guardedstruct do
sub_field(:list, list(struct()),
structs: true,
derive: "validate(list, not_empty)",
enforce: true
) do
field(:id, String.t(), enforce: true)
sub_field(:sublist, list(struct()),
structs: true,
derive: "validate(list, not_empty)",
enforce: true
) do
field(:id, String.t(), enforce: true)
end
end
end
end
assert {:ok, list} = NestedListStruct.builder(
%{
"list" => [
%{"id" => "1", "sublist" => [%{"id" => "2"}]}
]
}
)
# this error will be returned about missing required fields, but it's expected to work given struct definition
{:error, [%{field: :list, errors: [%{field: :sublist, errors: %{message: "Please submit required fields.", fields: [:id], action: :required_fields}}]}]}Also if sublist is renamed to list in both places struct and input, another issue occurs vs working as expected:
{:error, [%{field: :list, errors: [%{field: :list, errors: [%{message: "The list field must be list", field: :list, action: :list}]}]}]}
Reactions are currently unavailable