Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude empty paths from spec #583

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
zorbash marked this conversation as resolved.
Show resolved Hide resolved
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
Loading