{"id":17793362,"url":"https://github.com/lexmin0412/apifox-openapi","last_synced_at":"2026-02-23T20:06:23.592Z","repository":{"id":258321867,"uuid":"874668061","full_name":"lexmin0412/apifox-openapi","owner":"lexmin0412","description":"Apifox 开放接口 SDK","archived":false,"fork":false,"pushed_at":"2024-10-21T06:25:35.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-21T18:07:00.242Z","etag":null,"topics":["apifox","openapi"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lexmin0412.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-18T08:45:28.000Z","updated_at":"2024-10-21T06:25:39.000Z","dependencies_parsed_at":"2024-10-18T13:08:17.629Z","dependency_job_id":null,"html_url":"https://github.com/lexmin0412/apifox-openapi","commit_stats":null,"previous_names":["lexmin0412/apifox-openapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexmin0412%2Fapifox-openapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexmin0412%2Fapifox-openapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexmin0412%2Fapifox-openapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lexmin0412%2Fapifox-openapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lexmin0412","download_url":"https://codeload.github.com/lexmin0412/apifox-openapi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221667048,"owners_count":16860538,"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":["apifox","openapi"],"created_at":"2024-10-27T11:08:06.092Z","updated_at":"2026-02-23T20:06:23.524Z","avatar_url":"https://github.com/lexmin0412.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apifox-OpenApi\n\nApifox 开放 API 的 JavaScript SDK.\n\n![version](https://img.shields.io/npm/v/apifox-openapi) ![downloads-month](https://img.shields.io/npm/dm/apifox-openapi)\n\n## Roadmap\n\n- [x] 支持 Apifox 的所有开放 API\n- [ ] Playground\n\n## 前置准备\n\n首先你需要有一个 Apifox 项目，拿到这个项目的 ID，并创建一个访问令牌。\n\n获取方式：\n\n- 项目 ID：项目-\u003e项目设置-\u003e通用设置-\u003e基本设置\n- 访问令牌：右上角头像-\u003e账号设置-\u003eAPI 访问令牌\n\n## 用法 \n\n### 安装\n\n```shell\npnpm add apifox-openapi\n```\n\n### 初始化实例\n\n```js\nconst { ApifoxOpenApi } = require('apifox-openapi')\n\nconst instance = new ApifoxOpenApi({ \n  // Apifox 访问令牌\n  accessToken: 'APS-XXXX',\n  // Apifox 开放 API 版本\n  apiVersion: '2024-03-28',\n  // Apifox 项目 ID\n  projectId: '9999999',\n  // 语言\n  locale: 'zh-CN',\n})\n```\n\n### 导入 OpenAPI/Swagger 格式数据\n\n```js\nconst fs = require('fs')\nconst path = require('path')\n\nconst result = fs.readFileSync(path.resolve(__dirname, './openapiv3.json')).toString()\n\n// 导入 API\ninstance.importOpenApi(result).then((res)=\u003e{\n  console.log('导入成功', res)\n}).catch((err)=\u003e{\n  console.error('导入失败', err)\n})\n```\n\n### 导入 Postman Collection 格式数据\n\n```js\ninstance.importPostmanCollection().then((res)=\u003e{\n  console.log('导入成功', res)\n}).catch((err)=\u003e{\n  console.error('导入失败', err)\n})\n```\n\n### 导出 OpenAPI/Swagger 格式数据\n\n```js\ninstance.exportOpenApi().then((res)=\u003e{\n  console.log('导出成功', res)\n}).catch((err)=\u003e{\n  console.error('导出失败', err)\n})\n```\n\n## 最佳实践\n\n对于前后端分离并有 BFF 层的场景，往往需要前端同学在 BFF 和客户端代码中书写重复的请求代码、类型定义等，这个过程工作量较大且容易出错，如果后端接口发生变更往往牵一发而动全身。通过本仓库提供的功能仓库，我们可以使用自动化过程来解决这个问题。\n\n一个经过生产验证的最佳实践如下：\n\n1. 通过工具将 BFF 接口代码导出为 OpenAPI/Swagger 格式数据\n2. 通过 importOpenApi 将上一步的数据导入到 Apifox 项目中\n3. 通过 exportOpenApi 将 Apifox 项目导出 OpenAPI/Swagger 格式数据\n4. 通过工具将上一步中导出的数据转换为前端请求代码\n\n## 相关链接\n\n- [Apifox 开放 API](https://apifox-openapi.apifox.cn/doc-4296592)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexmin0412%2Fapifox-openapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flexmin0412%2Fapifox-openapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexmin0412%2Fapifox-openapi/lists"}