Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85805108
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/open_api_spex/cast_array.ex b/lib/open_api_spex/cast_array.ex
index 5d99c2f..81861d7 100644
--- a/lib/open_api_spex/cast_array.ex
+++ b/lib/open_api_spex/cast_array.ex
@@ -1,41 +1,39 @@
defmodule OpenApiSpex.CastArray do
@moduledoc false
alias OpenApiSpex.{Cast, CastContext}
def cast(%{value: []}) do
{:ok, []}
end
def cast(%{value: items} = ctx) when is_list(items) do
case cast_items(ctx) do
{items, []} -> {:ok, items}
{_, errors} -> {:error, errors}
end
end
def cast(ctx) do
CastContext.error(ctx, {:invalid_type, :array})
end
## Private functions
defp cast_items(%{value: items} = ctx) do
cast_results =
items
|> Enum.with_index()
|> Enum.map(fn {item, index} ->
path = [index | ctx.path]
Cast.cast(%{ctx | value: item, schema: ctx.schema.items, path: path})
end)
errors =
- Enum.flat_map(cast_results, fn
- {:error, errors} -> errors
- _ -> []
- end)
+ for({:error, errors} <- cast_results, do: errors)
+ |> Enum.concat()
items = for {:ok, item} <- cast_results, do: item
{items, errors}
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Oct 11, 1:26 AM (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1785526
Default Alt Text
(1 KB)
Attached To
Mode
R22 open_api_spex
Attached
Detach File
Event Timeline
Log In to Comment