Kafka + Phoenix + openAPI spec build errors

Hi all,
I’m working on a Phoenix project which uses the Open API Spex to generate a swagger front-end for testing our endpoints. We are in the process of connecting Kafka to the project at startup. When using mix openapi.spec.json --spec MyProj.ApiSpec, the following error is prompted and the build server fails to connect to Kafka.

** (Mix) Could not start application my_proj: MyProj.Application.start(:normal, []) returned an error: shutdown: failed to start child: MyProj.BrokerConn

I want to generate the API spec without attempting to connect to Kafka. Any help is much appreciated.

Hi and welcome to the forum.

Is MyProj.BrokerConn trying to connect to Kafka and failing when your app starts normally?

The task openapi.spec.json executes Mix.Task.run("app.start") so if that module is failing in your supervision tree it’s going to stop this task from running.


I would consider creating a custom mix task. The one that is included with OpenApiSpex is convenient for simple projects, but might not be suitable for all use cases.


Hello Juan, Thanks for reaching out and sorry for the delay. You were spot on!
I’m pretty new Elixir/Erlang; to what extent can I count on the the inherent fault tolerance of the supervision tree?

Hello Mike. Thanks a lot for the advice. As I told Juajn, I’ve just started to use Elixir; so writing a custom mix task seems a bit daunting at this stage. Would you recommend any particular resource/example to this end? Since I have to integrate other services into my codebase, I definitely need to up my skills to do what you have suggested.

The fault tolerance of starting your app is described by Supervisor.start_link/2

If the start function of any of the child processes fails or returns an error tuple or an erroneous value, the supervisor first terminates with reason :shutdown all the child processes that have already been started, and then terminates itself and returns {:error, {:shutdown, reason}}.

So if you have a child that’s failing to start you need to either, investigate why MyProj.BrokerConn is failing and fix it, remove it from the sup tree temporarily while you run the apispec task, or only add it to the tree if some environment flag isn’t set.

Otherwise take @mbuhot’s advice and copy the code from the openapi.spec.json task, removing Mix.Task.run("app.start"). I don’t have any experience with the package or Kafka so that’s the best advice at the moment.

1 Like