@nichozuo/gencode-ts-cli
v1.0.4
Published
A CLI tool to generate TypeScript code from OpenAPI specification
Downloads
352
Maintainers
Readme
gencode-ts-cli
一个从 OpenAPI 规范生成 TypeScript 代码的命令行工具。
安装
npm install -g @nichozuo/gencode-ts-cli
# 或
pnpm add -g @nichozuo/gencode-ts-cli使用方法
- 创建配置文件
gencode.json:
{
"url": "http://your-api-url/openapi",
"module": "Admin",
"outPath": "./output",
"apis": {
"firstLine": "import { MyResponseType } from '@/common'; import { request } from '@umijs/max';"
}
}- 运行命令:
# 使用当前目录的配置文件
gencode-ts
# 使用指定目录的配置文件
gencode-ts --configDir ./your-config-dir配置说明
url: OpenAPI 文档的 URLmodule: 模块名称outPath: 输出目录apis.firstLine: API 文件的首行导入语句
输出文件
工具会生成以下文件:
Apis.ts: API 调用代码ApiTypes.d.ts: API 类型定义Enums.ts: 枚举定义
