Skip to content

Commit

Permalink
Exclude empty paths from spec (#583)
Browse files Browse the repository at this point in the history
* Exclude empty paths from spec
  • Loading branch information
alisinabh committed Dec 18, 2023
1 parent 531607c commit ae71a1c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/open_api_spex/path_item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ defmodule OpenApiSpex.PathItem do
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
3 changes: 3 additions & 0 deletions test/paths_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ defmodule OpenApiSpex.PathsTest do
"/api/pets/{id}" => pets_path_item
} = paths

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

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 ae71a1c

Please sign in to comment.