{"id":17683268,"url":"https://github.com/haixiangyan/node-autodoc","last_synced_at":"2025-05-12T23:51:19.618Z","repository":{"id":106425785,"uuid":"362842112","full_name":"haixiangyan/node-autodoc","owner":"haixiangyan","description":"An API documentation generator driven by unit testing.","archived":false,"fork":false,"pushed_at":"2021-09-10T03:45:26.000Z","size":652,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T23:02:02.995Z","etag":null,"topics":["autodoc","docs","documentation"],"latest_commit_sha":null,"homepage":"http://yanhaixiang.com/node-autodoc/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haixiangyan.png","metadata":{"files":{"readme":"README-CN.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-04-29T14:18:55.000Z","updated_at":"2021-09-10T03:45:29.000Z","dependencies_parsed_at":"2023-07-16T00:13:04.432Z","dependency_job_id":null,"html_url":"https://github.com/haixiangyan/node-autodoc","commit_stats":null,"previous_names":["haixiang6123/node-autodoc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haixiangyan%2Fnode-autodoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haixiangyan%2Fnode-autodoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haixiangyan%2Fnode-autodoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haixiangyan%2Fnode-autodoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haixiangyan","download_url":"https://codeload.github.com/haixiangyan/node-autodoc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843167,"owners_count":21972868,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autodoc","docs","documentation"],"created_at":"2024-10-24T09:44:49.675Z","updated_at":"2025-05-12T23:51:19.592Z","avatar_url":"https://github.com/haixiangyan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-autodoc\n\n[![Coverage Status](https://coveralls.io/repos/github/Haixiang6123/node-autodoc/badge.svg?branch=main)](https://coveralls.io/github/Haixiang6123/node-autodoc?branch=main)\n[![Build Status](https://www.travis-ci.com/Haixiang6123/node-autodoc.svg?branch=main)](https://www.travis-ci.com/Haixiang6123/node-autodoc)\n![](https://img.shields.io/npm/l/node-autodoc)\n![](https://img.shields.io/npm/v/node-autodoc)\n\n[English](./README-CN.md)\n\n一个测试驱动文档的生成器。灵感来源于 [autodoc](https://github.com/r7kamura/autodoc) 和 [supertest](https://www.npmjs.com/package/supertest).\n\n## 为什么需要它\n\n对于大项目来说，很多人不喜欢维护 API 文档。新人接手的时候对着老接口就容易蒙逼，导致很多无效沟通。\n\n这个库可以在写简单接口测试用例时，直接根据测试用例，生成 API 文档。\n\n## 工作流\n\n![](./screenshot/flow.png)\n\n## 样例\n\n这个 repo 里也提供一个样例给大家食用，可以看 [这里](https://github.com/Haixiang6123/node-autodoc/tree/main/example)\n\n## 渲染方式\n\n### 默认渲染\n\n默认会使用 ejs 的模板引擎再结合默认模板来渲染 API 文档。\n\n### 自定义模板\n\n如果你想用自己的模板，更改 `templateDir` 指向你的模板文件夹即可。\n可以先参考 [默认模板](https://github.com/Haixiang6123/node-autodoc/tree/main/lib/templates) ，再制作你的模板。\n\n### 自定义渲染函数\n\n**如果你有更好的渲染方法，你也可以一个函数进 `renderPage` 里，来实现自定义渲染。**\n\n```js\nagent.renderPage((currentAgent) =\u003e {\n  // Assemable your render data\n  const myRenderData = {\n    title: currentAgent.title,\n    description: currentAgent.description,\n    docMetaCollection: currentAgent.docMetaCollection,\n    tableOfContent: currentAgent.docMetaCollection.map((docMeta) =\u003e ({\n      link: `#${encodeURIComponent(docMeta.title)}`,\n      title: docMeta.title,\n    })),\n  };\n  \n  // Your render function\n  customRender(myRenderData);\n})\n```\n\n**一个非常实用的操作是，将 `docMetaCollection` 发到自己的文档服务器上，再用这些数据生成文档网站。**\n\n## API\n\n很多使用方法都和 [supertest](https://www.npmjs.com/package/supertest) 很像。API 也很简单。\n\n新增的 API 如下。\n\n### AutoDocAgent\n\n```js\nconst agent = new AutoDocAgent(\n  app,\n  {\n    outputFilename: 'users.html',\n    title: 'Users API Documentation',\n    description: 'A small and simple documentation for how to deal with /users api',\n    outputDir,\n    templateDir,\n  }\n)\n```\n\n#### AutoDocAgent\n\n| 参数 | 描述 |\n|---|---|\n| app | Express 或者 KOA 应用 |\n| options | supertest Agent 的 options |\n\n\n#### options\n\n| 参数 | 描述 |\n|---|---|\n| outputFilename | 输出的 html 文件名 |\n| outputDir | 输出路径 |\n| templateDir | ejs 模板路径，不传值时默认使用 [默认模板](https://github.com/Haixiang6123/node-autodoc/tree/main/lib/templates)|\n| title | API 文档标题 |\n| description | API 文档描述 |\n\n### AutoDocAgent.clear\n\n清除 `outputDir` 路径下的内容.\n\n```js\nAutoDocAgent.clear(outputDir)\n```\n\n### AutoDocAgent.renderIndex\n\n给定 agents 列表渲染首页。\n\n```js\nAutoDocAgent.renderIndex({\n  title: 'My API Documentation',\n  description: 'This is my first documentation for testing, haha~',\n  author: 'Haixiang',\n  agents,\n  outputDir,\n  templateDir,\n});\n```\n\n| parameter | value |\n|---|---|\n| title | 首页标题 |\n| description | 首页描述 |\n| author | 作者名 |\n| agents | agents 列表 |\n| outputDir | 输出路径 |\n| templateDir | 模板路径. 不传值时使用[默认模板](https://github.com/Haixiang6123/node-autodoc/tree/main/lib/templates) |\n\n### restful 方法\n\n当调用 restful 方法时，其实是调用了 supertest 提供的 restful 方法。不同地方在于要多加第 2 个参数用于描述此次操作。\n\n```js\nagent.get('/users', {\n  title: 'Fetch all users',\n  description: 'To get all user infomation'\n})\n```\n\n### renderPage\n\n渲染当前页面\n\n```js\nagent.renderPage()\n```\n\n**一个非常实用的操作是，将 `docMetaCollection` 发到自己的文档服务器上，再用这些数据生成文档网站。**\n\n```js\nagent.renderPage((currentAgent) =\u003e {\n  // Assemable your render data\n  const myRenderData = {\n    title: currentAgent.title,\n    description: currentAgent.description,\n    docMetaCollection: currentAgent.docMetaCollection,\n    tableOfContent: currentAgent.docMetaCollection.map((docMeta) =\u003e ({\n      link: `#${encodeURIComponent(docMeta.title)}`,\n      title: docMeta.title,\n    })),\n  };\n  \n  // Your render function\n  customRender(myRenderData);\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaixiangyan%2Fnode-autodoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaixiangyan%2Fnode-autodoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaixiangyan%2Fnode-autodoc/lists"}