简体   繁体   English

REST API服务器的Hapi.js文档生成器

[英]Hapi.js Documentation generator for REST API Servers

I was looking for a tool that generates static documentation for Hapi.js routes, but doesn't create dependencies to the API server. 我一直在寻找一种工具,该工具可为Hapi.js路由生成静态文档,但不会创建对API服务器的依赖关系。

So I was just visualising a cli tool where I could pass my server.js as an argument, and would create the API documentation by parsing my route definitions. 因此,我只是可视化了一个cli工具,可以在其中传递server.js作为参数,并通过解析路由定义来创建API文档。

hapi-swagger modules fails, as it creates the follwoing dependencies to my server; hapi-swagger模块发生故障,因为它对我的服务器产生了以下依赖性;

  • Have to define a view engine 必须定义一个视图引擎
  • Have to disable the minimal option of my api servers 必须禁用我的api服务器的最小选项
  • Have to define a /documentation route (I know I can change that, but the issue persists) 必须定义/ documentation路由(我知道我可以更改它,但是问题仍然存在)

If such tool doesn't exists, what is the best alternative to create swagger ui static files documentation? 如果不存在这样的工具,那么创建swagger ui静态文件文档的最佳选择是什么?

Thanks! 谢谢!

First the lout module is officially supported by hapijs and is not deprecated. 首先,hapijs正式支持lout模块,并且不推荐使用。 It provides an alternative to swagger. 它提供了摇摇欲坠的替代方法。 But it does not solve your problem because it does not generate static html/css. 但这不能解决您的问题,因为它不会生成静态的html / css。

Now to the solution: I would add hapi-swagger but only in development like this (so you keep your server lightweight in staging/production)... 现在到解决方案:我将添加hapi-swagger,但仅在这样的开发中使用(以便在过渡/生产中使服务器保持轻量级)...

...
if (process.env.NODE_ENV === 'development') {
   //Register inert, vision, hapi-swagger with server.register()
}
...

...then use bootprint-swagger or something similar to generate static html which you can serve on a web server of your choice. ...然后使用bootprint-swagger或类似方法生成静态html,您可以在自己选择的网络服务器上使用它。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM