vscode插件
Parse controller file written by typescript, which helps to upload the api info to YAPI
Usage
environment:controller file written by typescript (support decorators)
- Add the yapi config file
yapi.json
to your project's root dir
{
"server": "host_of_your_yapi", // 内网yapi部署地址
"token": "your token of project", // for open api usage
"projectId": 0, // 项目id
- Just click
上传api信息
in the application

Example
// controller.ts
/**
* 订单类
*/
@Controller('/creative/template')
class C {
/**
* 获取订单详情
*/
@Get('/detail')
func1(input: Input): Output1 {
return {
out: ['aa']
};
}
/**
* 获取订单详情
*/
@Post('/update')
func2(input: Input): Promise<Output2> {
return Promise.resolve({
out: 'aa'
});
}
}
interface Input {
name: string;
/** 子属性1 */
desc?: { a: number };
inte: IInte;
children: Children;
}
interface IInte {
test: number;
}
type Children = {
/** 模板 */
template?: string;
}
interface Output1 {
/** 这是输出 */
out1: IInte[];
// out2: 1 | 2; not support yet...
}
interface Output2 {
/** 这是输出 */
out: string;
}
meta info
[
{
"name": "C",
"baseRouter": "'/creative/template'",
"controllersMeta": [
{
"name": "func1",
"comment": "获取订单详情",
"router": "'/detail'",
"method": "Get",
"input": [
{
"key": "name",
"type": "string",
"originType": "string",
"optional": false,
"comment": "",
"children": []
},
{
"key": "desc",
"type": "{ a: number; }",
"originType": "Object",
"optional": true,
"comment": "子属性1",
"children": [
{
"key": "a",
"type": "number",
"originType": "number",
"optional": false,
"comment": "",
"children": []
}
]
},
{
"key": "inte",
"type": "IInte",
"originType": "Object",
"optional": false,
"comment": "",
"children": [
{
"key": "test",
"type": "number",
"originType": "number",
"optional": false,
"comment": "",
"children": []
}
]
},
{
"key": "children",
"type": "Children",
"originType": "Object",
"optional": false,
"comment": "",
"children": [
{
"key": "template",
"type": "string",
"originType": "string",
"optional": true,
"comment": "模板",
"children": []
}
]
}
],
"output": [
{
"key": "out1",
"type": "IInte[]",
"originType": "Array",
"optional": false,
"comment": "这是输出",
"children": [
{
"key": "test",
"type": "number",
"originType": "number",
"optional": false,
"comment": "",
"children": []
}
]
}
]
},
{
"name": "func2",
"comment": "获取订单详情",
"router": "'/update'",
"method": "Post",
"input": [
{
"key": "name",
"type": "string",
"originType": "string",
"optional": false,
"comment": "",
"children": []
},
{
"key": "desc",
"type": "{ a: number; }",
"originType": "Object",
"optional": true,
"comment": "子属性1",
"children": [
{
"key": "a",
"type": "number",
"originType": "number",
"optional": false,
"comment": "",
"children": []
}
]
},
{
"key": "inte",
"type": "IInte",
"originType": "Object",
"optional": false,
"comment": "",
"children": [
{
"key": "test",
"type": "number",
"originType": "number",
"optional": false,
"comment": "",
"children": []
}
]
},
{
"key": "children",
"type": "Children",
"originType": "Object",
"optional": false,
"comment": "",
"children": [
{
"key": "template",
"type": "string",
"originType": "string",
"optional": true,
"comment": "模板",
"children": []
}
]
}
],
"output": [
{
"key": "out",
"type": "string",
"originType": "string",
"optional": false,
"comment": "这是输出",
"children": []
}
]
}
]
}
]
Roadmap
- 完善插件描述信息
- 完善解析核心能力
- [x] 解析controller类注释
- [x] 解析controller方法注释、装饰器、方法输入、输出参数以及参数对应的注释/是否必须
- [x] 解析类型声明中Promise<Res>的Res类型
- [x] 解析类型声明中的string[]、interface[]类型
- [ ] 解析类型声明中的enum、联合类型等
- [ ] 解析类型注释中的default/example/status
- [ ] 解析全局声明
- [ ] 程序健壮性增强
- 完善插件周期
- [x] 处理meta信息,生成api信息
- [x] 上传到api doc website
- [ ] 支持批量上传,比如整个项目一次性上传
- 优化部分逻辑
- [ ] diff同个controller文件的解析数据,避免每次都全量更新所有信息