Page MenuHomePhorge

No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None
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

Mime Type
text/x-diff
Expires
Sat, Nov 30, 2:51 PM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41482
Default Alt Text
(1 KB)

Event Timeline