使用说明
方式 1. 直接在.vscode/settings.json文件中添加如下配置
"swaggerApi.list": [
{
"title": "公共数据源",
"url": "openai.json",
"base": ""
}
方式 2. 通过右侧菜单工具图标添加
请求模板生成器 (request.template.js)
- 添加遵循openapi规范的接口json文档,自动生成请求模板
- 在项目根目录下创建
.vscode 文件夹
- 在文件夹内创建
request.template.cjs 文件
- 复制以下代码到文件中
模板代码
/**
* 生成请求模板
*
* @param {{
* base:基础请求路径
* path: 请求路径
* method: 请求方式
* Params: 路径请求的参数
* RequestBody: 请求体参数
* Response: 接口返回数据类型
* description: 接口描述文字
* name: 接口名称
* template: 生成的ts文件内容
* }}
*/
function requestTemplate(api) {
return requestTemplate = ""
}
module.exports = { requestTemplate }
生成示例
输入配置:
{
"name": "getUserInfo",
"base": "api/v1",
"path": "/user/info",
"method": "get",
"Params": [],
"Response": "UserInfo"
}
输出结果:
export const getUserInfo = async (params: getUserInfo.Params): Promise<getUserInfo.Response> => {
return http.get('api/v1/user/info', { params })
}
忽略更新注解(@ignore)
- 头部增加@ignore注解
| |