From 711f2ba79776f41a9e297c9fe487d1a814294016 Mon Sep 17 00:00:00 2001 From: Alisina Bahadori Date: Mon, 18 Dec 2023 10:21:50 -0500 Subject: [PATCH] fixup! Exclude empty paths from spec --- lib/open_api_spex/path_item.ex | 27 ++++++++++++--------------- lib/open_api_spex/paths.ex | 1 - 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/open_api_spex/path_item.ex b/lib/open_api_spex/path_item.ex index 584774f8..c7f0c585 100644 --- a/lib/open_api_spex/path_item.ex +++ b/lib/open_api_spex/path_item.ex @@ -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 diff --git a/lib/open_api_spex/paths.ex b/lib/open_api_spex/paths.ex index 10c25ce5..ba7b2e2f 100644 --- a/lib/open_api_spex/paths.ex +++ b/lib/open_api_spex/paths.ex @@ -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