我想使用https://github.com/smoku/phoenix_api_docs来制作一个doc api,但我有一个问题,正如文档中所指出的,我在test_helper.exs中放入了以下内容:
PhoenixApiDocs.start ExUnit.start(formatters: [ExUnit.CLIFormatter, PhoenixApiDocs.Formatter])当我运行mix测试时,控制台显示如下:
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中的文档。项目配置有erlang 19.2、elixir 1.4.2、Phoenix v1.2.4、nodejs 7.4.0、Erlang/OTP 20
在这种情况下我需要一些帮助
发布于 2017-07-29 12:44:40
phoenix_api_docs从mix.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,允许您配置路由器名称,并支持phoenix 1.3约定Support for Phoenix 1.3 #9
https://stackoverflow.com/questions/45331452
复制相似问题