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

Swagger & Slate Integration consistently erroring #100

Open
hgg opened this issue Jul 13, 2023 · 1 comment
Open

Swagger & Slate Integration consistently erroring #100

hgg opened this issue Jul 13, 2023 · 1 comment

Comments

@hgg
Copy link

hgg commented Jul 13, 2023

What I'm trying achieve

I'm trying to use the integration with Swagger & Slate to generate API docs automatically.
I've followed to the letter the guidelines.

What is happening

When I run DOC=1 mix test, all the tests pass but I get the following error:

11:09:17.606 [error] GenServer #PID<0.519.0> terminating
** (Protocol.UndefinedError) protocol Enumerable not implemented for nil of type Atom. This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Stream
    (elixir 1.14.5) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.14.5) lib/enum.ex:166: Enumerable.reduce/3
    (elixir 1.14.5) lib/enum.ex:1150: Enum.find/3
    (bureaucrat 0.2.9) lib/bureaucrat/swagger_slate_markdown_writer.ex:236: Bureaucrat.SwaggerSlateMarkdownWriter.write_operations_for_tag/4
    (elixir 1.14.5) lib/enum.ex:975: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir 1.14.5) lib/enum.ex:1662: anonymous fn/3 in Enum.map/2
    (stdlib 5.0.2) maps.erl:416: :maps.fold_1/4
    (elixir 1.14.5) lib/enum.ex:2480: Enum.map/2
    (bureaucrat 0.2.9) lib/bureaucrat/formatter.ex:22: Bureaucrat.Formatter.suite_finished/0
    (stdlib 5.0.2) gen_server.erl:1103: :gen_server.try_handle_cast/3
    (stdlib 5.0.2) gen_server.erl:1165: :gen_server.handle_msg/6
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_cast", {:suite_finished, %{async: 163093, run: 509077, load: nil}}}
11:09:17.612 [error] Task #PID<0.501.0> started from #PID<0.101.0> terminating
** (stop) exited in: GenServer.stop(#PID<0.519.0>, :normal, :infinity)
    ** (EXIT) exited in: :sys.terminate(#PID<0.519.0>, :normal, :infinity)
        ** (EXIT) an exception was raised:
            ** (Protocol.UndefinedError) protocol Enumerable not implemented for nil of type Atom. This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Stream
                (elixir 1.14.5) lib/enum.ex:1: Enumerable.impl_for!/1
                (elixir 1.14.5) lib/enum.ex:166: Enumerable.reduce/3
                (elixir 1.14.5) lib/enum.ex:1150: Enum.find/3
                (bureaucrat 0.2.9) lib/bureaucrat/swagger_slate_markdown_writer.ex:236: Bureaucrat.SwaggerSlateMarkdownWriter.write_operations_for_tag/4
                (elixir 1.14.5) lib/enum.ex:975: Enum."-each/2-lists^foreach/1-0-"/2
                (elixir 1.14.5) lib/enum.ex:1662: anonymous fn/3 in Enum.map/2
                (stdlib 5.0.2) maps.erl:416: :maps.fold_1/4
                (elixir 1.14.5) lib/enum.ex:2480: Enum.map/2
                (bureaucrat 0.2.9) lib/bureaucrat/formatter.ex:22: Bureaucrat.Formatter.suite_finished/0
                (stdlib 5.0.2) gen_server.erl:1103: :gen_server.try_handle_cast/3
                (stdlib 5.0.2) gen_server.erl:1165: :gen_server.handle_msg/6
                (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
    (elixir 1.14.5) lib/gen_server.ex:995: GenServer.stop/3
    (ex_unit 1.14.5) lib/ex_unit/event_manager.ex:22: anonymous fn/2 in ExUnit.EventManager.stop/1
    (elixir 1.14.5) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ex_unit 1.14.5) lib/ex_unit/event_manager.ex:21: ExUnit.EventManager.stop/1
    (ex_unit 1.14.5) lib/ex_unit/runner.ex:62: ExUnit.Runner.run_with_trap/2
    (ex_unit 1.14.5) lib/ex_unit/runner.ex:31: ExUnit.Runner.run/2
    (elixir 1.14.5) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
    (elixir 1.14.5) lib/task/supervised.ex:34: Task.Supervised.reply/4
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Function: #Function<0.96829595/0 in ExUnit.async_run/0>
    Args: []
** (EXIT from #PID<0.101.0>) exited in: GenServer.stop(#PID<0.519.0>, :normal, :infinity)
    ** (EXIT) exited in: :sys.terminate(#PID<0.519.0>, :normal, :infinity)
        ** (EXIT) an exception was raised:
            ** (Protocol.UndefinedError) protocol Enumerable not implemented for nil of type Atom. This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Stream
                (elixir 1.14.5) lib/enum.ex:1: Enumerable.impl_for!/1
                (elixir 1.14.5) lib/enum.ex:166: Enumerable.reduce/3
                (elixir 1.14.5) lib/enum.ex:1150: Enum.find/3
                (bureaucrat 0.2.9) lib/bureaucrat/swagger_slate_markdown_writer.ex:236: Bureaucrat.SwaggerSlateMarkdownWriter.write_operations_for_tag/4
                (elixir 1.14.5) lib/enum.ex:975: Enum."-each/2-lists^foreach/1-0-"/2
                (elixir 1.14.5) lib/enum.ex:1662: anonymous fn/3 in Enum.map/2
                (stdlib 5.0.2) maps.erl:416: :maps.fold_1/4
                (elixir 1.14.5) lib/enum.ex:2480: Enum.map/2
                (bureaucrat 0.2.9) lib/bureaucrat/formatter.ex:22: Bureaucrat.Formatter.suite_finished/0
                (stdlib 5.0.2) gen_server.erl:1103: :gen_server.try_handle_cast/3
                (stdlib 5.0.2) gen_server.erl:1165: :gen_server.handle_msg/6
                (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

What I've tried

  • Adding the operation_id(...) to the operations in question.
    FYI this is missing from the guidelines. Let me know if you'd like me to add it.

Am I missing something? The swagger.json file seems to be being generated fine, but both the markdown and the HTML generated from it don't include any operations.

@hgg
Copy link
Author

hgg commented Jul 13, 2023

I got it working. I had to pass the operation_ids I'm using as elements on the tags field of the swagger_info object that is defined on the router. Shouldn't this be in the guidelines too?
example

  def swagger_info do
    %{
      info: %{
        version: "0.1",
        title: "Funky API"
      },
      basePath: "/api",
      tags: [
        %{name: "users", description: "Operations about Users"},
        # operation_ids
        %{name: "list_users", description: "List Users operation"},
        %{name: "invite_users", description: "Invite Users operation"}
      ]
    }
  end

EDIT: Just want to clearly state that I'm happy to provide a PR with these improvements 😁

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