Skip to content

seho-code-life/yapi-interface-extension

 
 

Repository files navigation

yapi-interface-extension

一个 YAPI 浏览器插件,在 YAPI 接口文档显示 TypeScript interface。

Install

  1. clone 项目,执行 yarn install
  2. 新增且修改 public/manifest.json 文件的 matches 字段,将 www.xxx.com 改为你部署的 YAPI 域名。
{
  "name": "Yapi-Interface-Extension",
  "manifest_version": 2,
  "version": "1.2.1",
  "author": "seho",
  "description": "在 YAPI 接口文档中显示 TypeScript Interface",
  "icons": {
    "64": "icon-64.png"
  },
  "content_scripts": [
    {
      "matches": ["*://www.xxx.com/*"], // 例如www.baidu.com
      "js": ["content/main.js"],
      "run_at": "document_start"
    }
  ],
  "web_accessible_resources": ["inject/*.js"],
  "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self';"
}
  1. 执行 yarn build,将生成后的 dist 文件夹拖入 chrome 插件页面。

新增特性

对于 Rest API, url 中不会体现动词,add, update, delete 等等,对于这一类 url,插件会自动根据 methods 推断一个动词自动加在 TS 类型声明中,如果推断不符合业务场景,需要开发者自行修改。

为了前端更方便的获得类型提示,在开发中要对 api url 有一定的要求,所以后端开发需要尽可能得贴合rest 风格

method 和动词的字典如下:

const methodMap: Record<string, string> = {
  GET: 'Get',
  POST: 'Create',
  PUT: 'Update',
  DELETE: 'Delete'
}

Example

Example

伴生模板 💗

和它使用能发挥更好的作用

License

This project is licensed under the MIT License - see the LICENSE file for details

About

一个 YAPI 浏览器插件,在 YAPI 接口文档显示 TypeScript interface。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 87.5%
  • JavaScript 11.6%
  • Shell 0.9%