When attempting to start a project that uses phoenix_swagger with Elixir 1.14.0-rc.0, an error occurs related to the usage of the |> operator within the swagger_path macro. This error is caused by a change in the behavior of the |> operator in the new Elixir version.
Steps to Reproduce:
Set up a Phoenix project that uses phoenix_swagger.
Update Elixir to version 1.14.0-rc.0.
Attempt to start the project with mix phx.server.
Expected Behavior:
The project should start without errors.
Observed Behavior:
The compiler raises the following error:
** (ArgumentError) cannot pipe %PhoenixSwagger.Path.PathObject{} into get("/users") |> description("List blog posts") |> response(200, "Success"), the :|> operator can only take two arguments
(elixir 1.14.0-rc.0) lib/macro.ex:323: Macro.pipe/3
(elixir 1.14.0-rc.0) expanding macro: Kernel.|>/2
Environment:
Elixir version: 1.14.0-rc.0
Possible Solution:
The issue can be resolved by modifying the swagger_path macro to avoid the incorrect use of the |> operator. Here's the proposed implementation:
defmacro swagger_path(action, [do: {:__block__, _, block_exprs}]) do
fun_name = "swagger_path_#{action}" |> String.to_atom
body = Enum.reduce(block_exprs, quote do %PhoenixSwagger.Path.PathObject{} end, fn expr, acc ->
quote do
unquote(acc)
|> unquote(expr)
end
end)
quote do
def unquote(fun_name)(route) do
import PhoenixSwagger.Path
unquote(body)
|> PhoenixSwagger.ensure_operation_id(__MODULE__, unquote(action))
|> PhoenixSwagger.ensure_tag(__MODULE__)
|> PhoenixSwagger.ensure_verb_and_path(route)
|> PhoenixSwagger.Path.nest()
|> PhoenixSwagger.to_json()
end
end
end
Problem Description:
When attempting to start a project that uses
phoenix_swagger
with Elixir 1.14.0-rc.0, an error occurs related to the usage of the|>
operator within theswagger_path
macro. This error is caused by a change in the behavior of the|>
operator in the new Elixir version.Steps to Reproduce:
phoenix_swagger
.mix phx.server
.Expected Behavior:
The project should start without errors.
Observed Behavior:
The compiler raises the following error:
** (ArgumentError) cannot pipe %PhoenixSwagger.Path.PathObject{} into get("/users") |> description("List blog posts") |> response(200, "Success"), the :|> operator can only take two arguments (elixir 1.14.0-rc.0) lib/macro.ex:323: Macro.pipe/3 (elixir 1.14.0-rc.0) expanding macro: Kernel.|>/2
Environment:
Possible Solution:
The issue can be resolved by modifying the
swagger_path
macro to avoid the incorrect use of the|>
operator. Here's the proposed implementation: