简体   繁体   English

为用 Express 4.x 编写的 API 创建 Swagger 文档

[英]Create Swagger-docs for API written in Express 4.x

I have a server written with Node and Express 4. I also have a customer which wants this to be documented with Swagger.我有一个用 Node 和 Express 4 编写的服务器。我也有一个客户希望用 Swagger 记录这一点。 How can this be done?如何才能做到这一点?

I've looked into the following tools:我研究了以下工具:

  • swagger-node-express : Lets you do exactly what I want, except it does not support Express 4.x swagger-node-express :让你做我想做的,除了它不支持 Express 4.x
  • Swagger 2.0 - Node-Express-4.x : Same as above but with a different approach. Swagger 2.0 - Node-Express-4.x :与上面相同,但采用不同的方法。 Could be used, except I don't find much documentation on setting it up (and I'm too slow to get it without docs)可以使用,除了我没有找到太多关于设置它的文档(而且我在没有文档的情况下获取它太慢了)

Tools like swaggerize-express and Swaggers own tool for Node would work if I started from scratch, but I just want a way to easiliy add docs to my project so that Swagger can read it.如果我从头开始,像swaggerize -expressSwaggers 自己的 Node工具这样的工具会起作用,但我只是想要一种方法来轻松地将文档添加到我的项目中,以便 Swagger 可以阅读它。

It wouldn't work in the long run to write a doc-file that Swagger can read because then I'd have to update it.从长远来看,编写 Swagger 可以读取的文档文件是行不通的,因为那样我就必须更新它。 I want to document everything in the code and not a Swagger- or readme-file, and let the documentation be available through a Swagger-UI automatically.我想记录代码中的所有内容,而不是 Swagger 或自述文件,并让文档自动通过 Swagger-UI 可用。

I may have overlooked something here, but I can't seem to find anything to help me.All suggestions are welcome.我可能在这里忽略了一些东西,但我似乎找不到任何可以帮助我的东西。欢迎所有建议。 Thanks in advance.提前致谢。

I highly recommend looking into Loopback framework.我强烈建议研究Loopback框架。 It's framework for creating REST APIs on stereoids.它是在stereoids 上创建REST API 的框架。 It is using Express under the hood and is created by company StrongLoop, which also maintains Express project itself now.它在幕后使用 Express,由 StrongLoop 公司创建,该公司现在也维护Express 项目本身。

It supports Swagger out of the box.它支持开箱即用的 Swagger。

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

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