使用phoenix_api_docs

我想用https://github.com/smoku/phoenix_api_docs来创build一个doc api,但是我遇到了一个问题,正如文档中所指出的那样,我把test_helper.exs放在了这里:

PhoenixApiDocs.start ExUnit.start(formatters: [ExUnit.CLIFormatter, PhoenixApiDocs.Formatter]) 

当我运行混合testing,控制台显示我这样的:

 09:22:51.173 [error] GenEvent handler PhoenixApiDocs.Formatter installed in #PID<0.323.0> terminating ** (UndefinedFunctionError) function WhitespaceEx.Application.Router.__routes__/0 is undefined (module WhitespaceEx.Application.Router is not available) WhitespaceEx.Application.Router.__routes__() (phoenix_api_docs) lib/phoenix_api_docs/generator.ex:26: PhoenixApiDocs.Generator.routes_docs/2 (phoenix_api_docs) lib/phoenix_api_docs/generator.ex:12: PhoenixApiDocs.Generator.run/0 (phoenix_api_docs) lib/phoenix_api_docs/formatter.ex:22: PhoenixApiDocs.Formatter.save_blueprint_file/0 (phoenix_api_docs) lib/phoenix_api_docs/formatter.ex:9: PhoenixApiDocs.Formatter.handle_event/2 (stdlib) gen_event.erl:573: :gen_event.server_update/4 (stdlib) gen_event.erl:555: :gen_event.server_notify/4 (stdlib) gen_event.erl:296: :gen_event.handle_msg/6 (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3 Last message: {:suite_finished, 6679713, nil} 

并且不会生成文件api.apib中的文档。 项目configuration有erlang 19.2elixir 1.4.2Phoenix v1.2.4nodejs 7.4.0Erlang/OTP 20

在这种情况下,我想要一些帮助

phoenix_api_docsmix.exs指定的应用程序模块推断您的路由器模块的名称:

  def run do test_conns = PhoenixApiDocs.ConnLogger.conns app_module = Mix.Project.get.application |> Keyword.get(:mod) |> elem(0) router_module = Module.concat([app_module, :Router]) %{ host: Keyword.get(api_docs_info, :host, "http://localhost"), title: Keyword.get(api_docs_info, :title, "API Documentation"), description: Keyword.get(api_docs_info, :description, "Enter API description in mix.exs - api_docs_info"), routes: routes_docs(router_module, test_conns) } end 

从你的错误信息,它看起来像你的应用程序模块名称是WhitespaceEx.Application ,但我想你的路由器模块是WhitespaceEx.Router

一种使当前的phoenix_api_docs实现工作的方法是将应用程序模块重命名为WhitespaceEx

有一个开放的PR,将允许您configuration路由器名称,并支持凤凰1.3约定支持凤凰1.3#9