Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>CloudAPINew to Visual Studio Code? Get it now.
CloudAPI

CloudAPI

yuwang

|
331 installs
| (0) | Free
CloudAPI client for VSCode
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

CloudAPI README

注意:这里的文档不完整,请到 http://confluence.qunhequnhe.com/pages/viewpage.action?pageId=130093359 查看

快速拉取 YAPI 上的接口的信息并生成对应的 API 层代码。配合 @qunhe/cloudapi-loader 可以检测到接口文档的不规范改动,提前暴露问题

使用说明

只需要键入 import xxx from '@cloudapi/' 即可完成自动匹配 使用说明

如果需要使用 qunhe/pluto 中的高级功能,暂时可以这样写

import _withdrawApproval from '@cloudapi/G-43-saas/P-934-商家后台/C-13244-审批/C-13245-新增用户审批/I-47372-撤回审批';
import pluto, { operationLogger, queryLogger } from '@qunhe/pluto';

export default class API {
    @operationLogger()
    static withdrawApproval(...params: Parameters<typeof _withdrawApproval>) {
        return _withdrawApproval(...params);
    }
}

设置

安装依赖

CloudAPI 依赖于 @qunhe/pluto,这是一个基于 axios 的封装,详细可见文档 http://manual.k8s-new.qunhequnhe.com/pluto

yarn add @qunhe/pluto
yarn add @qunhe/cloudapi-loader -D

配置 CloudAPI

在项目根目录下新建 .cloudapirc.{js|json} 文件,包含以下配置项

  • outDir:必须,指定生成接口存放的文件夹
  • interfacePrefix:非必须,指定生成接口的 interface 名称的前缀,默认为 「CloudAPI」
  • 其余 prettier 支持的属性,非必须,这里的属性值优先级高于项目里 .prettierrc 定义的属性 在 tsconfig.json 中,新增
{
    "compilerOptions": {
        //...
        "paths": {
            "@cloudapi/*": ["path/to/cloudapi/outdir/*"],
        },
    }
}

在 webpack 中,新增

{
    // webpack.config.js
    //...
    resolve: {
        // ...,
        alias: {
            // ...,
            '@cloudapi': 'path/to/cloudapi/outdir'
        }
    }
}

配置 cloudapi-loader

在 webpack 中,ts 文件,需要新增 @qunhe/cloudapi-loader,并确保该 loader 是最后一项:

{
    // webpack.config.js
    //...
    module: {
        rules: [{
            test: /\.tsx?$/,
            exclude: /node_modules/,
            use: [{
                loader: 'ts-loader',
            }, {
                loader: '@qunhe/cloudapi-loader'
            }]
        }]
    },
}
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft