node.js api文檔生成


ApiDoc官網地址為:http://apidocjs.com/
在Java中有Swagger及其升級版的Swagger2+Springfox自動生成接口管理文檔。而在Node.js中則可以利用ApiDoc生成接口文檔。

參考官網其實步驟,也很簡單,也就如下幾步。

一、安裝庫


npm i apidoc -g   #全局安裝

二、配置package.json

{
  "name": "mock-github-api",
  "version": "1.0.0",
  "description": "Mock API server for Github",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/mzabriskie/mock-github-api"
  },
  "author": "Matt Zabriskie",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/mzabriskie/mock-github-api/issues"
  },
  "homepage": "https://github.com/mzabriskie/mock-github-api",
  "dependencies": {
    "@octokit/app": "^2.2.1",
    "apidoc": "^0.17.7",
    "color": "^0.11.3",
    "connect-multiparty": "^2.2.0",
    "cors": "^2.7.1",
    "cos-nodejs-sdk-v5": "^2.5.6",
    "express": "^4.14.0",
    "faker": "^3.1.0",
    "https": "^1.0.0",
    "multer": "^1.4.1",
    "multiparty": "^4.2.1",
    "mysql": "^2.16.0",
    "octokit": "^1.0.0-hello-world",
    "redis": "^2.8.0"
  },
"apidoc": {  
    "title": "接口文檔", 
    "url": "http://localhost:3000"
  }
}

三、在public目錄下創建apidoc目錄

四、使用命令生成apidoc文檔

訪問地址:http://localhost:3000/apidoc/index.html
效果圖如下所示:

源碼地址為:https://github.com/developers-youcong/mock-github-api


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM