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

Incompatibility with Elixir 1.14.0-rc.0: |> operator error in swagger_path macro #295

Open
leonardanyer opened this issue Aug 29, 2024 · 0 comments

Comments

@leonardanyer
Copy link

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 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:

  1. Set up a Phoenix project that uses phoenix_swagger.
  2. Update Elixir to version 1.14.0-rc.0.
  3. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant