Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>zapi-pluginNew to Visual Studio Code? Get it now.
zapi-plugin

zapi-plugin

myamo

|
136 installs
| (0) | Free
ZanApi service code generator
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

zapi-plugin README

zapi-plugin is a code generator for Zan-Api

使用方法

右键工作区触发(service文件生成在当前目录)


shift + commnd + p 触发 (按照特定规则,详见Service文件生成路径规则)

首次使用提示需要登录cas账号

输入zan-api文档地址最后的数字

代码生成时,vscode窗口左下角会有进度提示

命令

gencode - 根据ZanApi methodId生成service文件

调用命令后在输入框内输入 methodId,多个methodId以空格隔开

methodId eg: http://zanapi.qima-inc.com/site/service/view/243133 => 243133


genset - 根据ZanApi collectionId 生成service文件

调用命令后在输入框内输入 collectionId,多个collectionId以空格隔开

collectionId eg: http://zanapi.qima-inc.com/site/collection/3330 => 3330

Service文件生成路径规则

1. 右键工作区文件夹执行gencode或genset,会将生成的service文件保存在当前文件夹,若该service文件已存在则将代码添加到原文件中(不推荐)
  1. 直接执行gencode或genset会将service文件写入当前工作区该路径下:(astroboy工程推荐)
    app/services/api/x1/x2/ServiceName.js
    eg: http://zanapi.qima-inc.com/site/service/view/243133
    方法全名:com.name.x1.x2.x3.x4.TestWebApiService.testMethod
    取第3,4个域(x1和x2),最终结果app/services/api/x1/x2/TestWebApiService.js

  2. 自定义生成规则(非右键工作区文件夹执行gencode或genset的情况生效)

1⃣ 点击 Code/首选项/设置

2️⃣ 扩展/zapi-plugin

3️⃣ 配置项解释:

Reg: 与方法全名做匹配的正则

Path Format: service文件生成目录的规则

ServiceNameFormat: service文件名生成规则

UseDefaultRuleOnFail: 勾选该选项 方法全名与Reg未匹配时,忽略PathFormat和ServiceNameFormat,按照默认规则生成

示例1(自动给ServiceName补上Service后缀):

名称:      
 com.name.x1.x2.x3.x4.TestWebApiService.testMethod

配置:

  Reg: \w+\.\w+\.(\w+)\.(\w+)\..+\.(\w+)Service{0,1}\.\w+

  Path Format: /{1}/{2}

  Service Name Format: {3}Service

结果:

  Service Path: app/services/api/x1/x2
  // app/services/api + /{1}/{2} = app/services/api/x1/x2

  Service Name: TestWebApiService 
  // {3}Service = TestWebApiService 
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft