Skip to content

Commit

Permalink
Exclude empty paths from spec
Browse files Browse the repository at this point in the history
  • Loading branch information
alisinabh committed Dec 12, 2023
1 parent 531607c commit 4b01a1b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/open_api_spex/path_item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ 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

Expand Down
1 change: 1 addition & 0 deletions lib/open_api_spex/paths.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ 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
2 changes: 2 additions & 0 deletions test/paths_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ defmodule OpenApiSpex.PathsTest do
"/api/pets/{id}" => pets_path_item
} = paths

refute Map.has_key?(paths, "/api/noapi")

assert pets_path_item.patch.operationId == "OpenApiSpexTest.PetController.update"
assert pets_path_item.put.operationId == "OpenApiSpexTest.PetController.update (2)"
end
Expand Down

0 comments on commit 4b01a1b

Please sign in to comment.