diff --git a/lib/open_api_spex/path_item.ex b/lib/open_api_spex/path_item.ex index 82042707..c7f0c585 100644 --- a/lib/open_api_spex/path_item.ex +++ b/lib/open_api_spex/path_item.ex @@ -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 diff --git a/test/paths_test.exs b/test/paths_test.exs index 300e9497..3d633395 100644 --- a/test/paths_test.exs +++ b/test/paths_test.exs @@ -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