Skip to content

Commit

Permalink
fixup! Exclude empty paths from spec
Browse files Browse the repository at this point in the history
  • Loading branch information
alisinabh committed Dec 18, 2023
1 parent 4b01a1b commit 711f2ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
27 changes: 12 additions & 15 deletions lib/open_api_spex/path_item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,21 @@ defmodule OpenApiSpex.PathItem do
|> from_valid_routes()
end

def empty?(%__MODULE__{} = path_item) do
path_item == %__MODULE__{}
end

@spec from_valid_routes([route]) :: nil | t
defp from_valid_routes([]), do: nil

defp from_valid_routes(routes) do
attrs =
routes
|> Enum.map(fn route ->
case Operation.from_route(route) do
nil -> nil
op -> {route.verb, op}
end
end)
|> Enum.filter(& &1)

struct(PathItem, attrs)
routes
|> Enum.map(fn route ->
case Operation.from_route(route) do
nil -> nil
op -> {route.verb, op}
end
end)
|> Enum.filter(& &1)
|> case do
[] -> nil
attrs -> struct(PathItem, attrs)
end
end
end
1 change: 0 additions & 1 deletion lib/open_api_spex/paths.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ defmodule OpenApiSpex.Paths do
|> Enum.group_by(fn route -> route.path end)
|> Enum.map(fn {k, v} -> {open_api_path(k), PathItem.from_routes(v)} end)
|> Enum.filter(fn {_k, v} -> !is_nil(v) end)
|> Enum.reject(fn {_k, v} -> PathItem.empty?(v) end)
|> Map.new()

paths
Expand Down

0 comments on commit 711f2ba

Please sign in to comment.