UNPKG

@magicbe/api-generator

Version:

api 生成器

59 lines (49 loc) 2.15 kB
API 代码生成器 - 使用帮助 使用方法: gen-api [选项] gen-api --config <配置文件路径> 选项: --type <type> API 平台类型: yapi | swagger (必填) --service <url> API 服务地址 (必填) --output <path> 输出目录路径 (必填) --target <target> 目标语言: typescript | javascript (必填) --token <token> YApi 访问令牌 (YApi 需要) --cats <ids> YApi 分类 ID,多个用逗号分隔 (YApi 可选) --resources <names> Swagger 资源名称,多个用逗号分隔 (Swagger 可选) --function <path> 请求函数导入路径 (可选,默认: @/request) --headers <json> 自定义请求头,JSON 格式 (Swagger 可选) --config <path> 配置文件路径 (可选,默认: ./api-generator.config.json) --help, -h 显示此帮助信息 配置文件格式 (api-generator.config.json): { "type": "yapi", "service": "https://your-yapi-domain.com", "token": "your-api-token", "output": "./src/api", "target": "typescript", "function": "@/utils/request", "cats": [123, 456], "headers": { "Cookie": "your-cookie" } } 示例: # 使用命令行参数 gen-api --type yapi --service https://yapi.example.com --token your-token --output ./src/api --target typescript # 使用配置文件 gen-api --config ./my-config.json # 只生成指定分类的 API (YApi) gen-api --type yapi --service https://yapi.sugonup.com --target typescript --output ./test/request/modules --function --token 6229e82bed60ed92c3142500e92043c914a4ec441220dae431769792c80 # 生成指定资源的 API (Swagger) gen-api --type swagger --service https://swagger.example.com/swagger.json --output ./src/api --target typescript --resources user,order 支持的 API 平台: - YApi: https://github.com/YMFE/yapi - Swagger/OpenAPI: https://swagger.io/ 生成的代码: - TypeScript/JavaScript 接口定义 - 类型安全的请求函数 - 完整的 JSDoc 注释 - 自动格式化的代码 更多信息: - GitHub: http://www.wangquan.top - 文档: 参见 README.md