swagger2api-v3 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +68 -66
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,39 +1,41 @@
1
1
  # Swagger2API-v3
2
2
 
3
- 一个强大的命令行工具,用于从 Swagger(OAS3.0) 文档自动生成 TypeScript 接口代码。
3
+ English | [中文](./README_CN.md)
4
4
 
5
- ## 特性
5
+ A powerful command-line tool for automatically generating TypeScript interface code from Swagger (OAS3.0) documentation.
6
6
 
7
- - 🚀 **快速生成** - 从 Swagger JSON 快速生成 TypeScript 接口代码
8
- - 📁 **智能分组** - 支持按 Swagger 标签自动分组生成文件
9
- - 📝 **详细注释** - 自动生成包含描述、参数、返回值的详细注释
10
- - 🎨 **代码格式化** - 支持自定义格式化命令
11
- - ⚙️ **环境适配** - 自动检测项目环境,生成对应格式的配置文件
12
- - 🔧 **CLI 工具** - 提供完整的命令行工具
7
+ ## Features
13
8
 
14
- ## 📦 安装
9
+ - 🚀 **Fast Generation** - Quickly generate TypeScript interface code from Swagger JSON
10
+ - 📁 **Smart Grouping** - Support automatic file grouping by Swagger tags
11
+ - 📝 **Detailed Comments** - Automatically generate detailed comments including descriptions, parameters, and return values
12
+ - 🎨 **Code Formatting** - Support custom formatting commands
13
+ - ⚙️ **Environment Adaptation** - Automatically detect project environment and generate corresponding configuration files
14
+ - 🔧 **CLI Tool** - Provide complete command-line tools
15
+
16
+ ## 📦 Installation
15
17
 
16
18
  ```bash
17
- # 全局安装
19
+ # Global installation
18
20
  npm install -g swagger2api-v3
19
21
 
20
- # 项目依赖
22
+ # Project dependency
21
23
  npm install swagger2api-v3
22
24
  ```
23
25
 
24
- ## 🚀 快速开始
26
+ ## 🚀 Quick Start
25
27
 
26
- ### 1. 初始化配置文件
28
+ ### 1. Initialize Configuration File
27
29
 
28
30
  ```bash
29
31
  npx swagger2api-v3 init
30
32
  ```
31
33
 
32
- ### 2. 配置文件说明
34
+ ### 2. Configuration File Description
33
35
 
34
- 工具会根据项目环境自动生成对应格式的配置文件:
36
+ The tool automatically generates configuration files in the corresponding format based on the project environment:
35
37
 
36
- **CommonJS 环境** (`"type": "commonjs"` 或未设置)
38
+ **CommonJS Environment** (`"type": "commonjs"` or not set):
37
39
  ```javascript
38
40
  const config = {
39
41
  input: 'https://petstore.swagger.io/v2/swagger.json',
@@ -52,80 +54,80 @@ const config = {
52
54
  module.exports = config;
53
55
  ```
54
56
 
55
- **ES 模块环境** (`"type": "module"`)
57
+ **ES Module Environment** (`"type": "module"`):
56
58
  ```javascript
57
59
  const config = {
58
- // ... 相同配置
60
+ // ... same configuration
59
61
  };
60
62
 
61
63
  export default config;
62
64
  ```
63
65
 
64
- ### 3. 生成接口代码
66
+ ### 3. Generate Interface Code
65
67
 
66
68
  ```bash
67
69
  npx swagger2api-v3 generate
68
70
  ```
69
71
 
70
- ## ⚙️ 配置选项
72
+ ## ⚙️ Configuration Options
71
73
 
72
- | 选项 | 类型 | 默认值 | 说明 |
73
- |------|------|--------|------|
74
- | `input` | string | - | Swagger JSON 文件路径或 URL |
75
- | `output` | string | `'./src/api'` | 生成代码的输出目录 |
76
- | `generator` | string | `'typescript'` | 代码生成器类型 |
77
- | `groupByTags` | boolean | `true` | 是否按标签分组生成文件 |
78
- | `overwrite` | boolean | `true` | 是否覆盖已存在的文件 |
79
- | `prefix` | string | `''` | 接口路径公共前缀 |
80
- | `importTemplate` | string | - | request 函数导入语句模板 |
81
- | `lint` | string | - | 代码格式化命令(可选) |
82
- | `options.addComments` | boolean | `true` | 是否添加详细注释 |
74
+ | Option | Type | Default | Description |
75
+ |--------|------|---------|-------------|
76
+ | `input` | string | - | Swagger JSON file path or URL |
77
+ | `output` | string | `'./src/api'` | Output directory for generated code |
78
+ | `generator` | string | `'typescript'` | Code generator type |
79
+ | `groupByTags` | boolean | `true` | Whether to group files by tags |
80
+ | `overwrite` | boolean | `true` | Whether to overwrite existing files |
81
+ | `prefix` | string | `''` | Common prefix for API paths |
82
+ | `importTemplate` | string | - | Import statement template for request function |
83
+ | `lint` | string | - | Code formatting command (optional) |
84
+ | `options.addComments` | boolean | `true` | Whether to add detailed comments |
83
85
 
84
- ## 📁 生成的文件结构
86
+ ## 📁 Generated File Structure
85
87
 
86
- ### 按标签分组 (推荐)
88
+ ### Grouped by Tags (Recommended)
87
89
 
88
90
  ```
89
91
  src/api/
90
- ├── types.ts # 数据类型定义
91
- ├── user/ # User 相关接口
92
+ ├── types.ts # Data type definitions
93
+ ├── user/ # User-related APIs
92
94
  │ └── index.ts
93
- ├── auth/ # Auth 相关接口
95
+ ├── auth/ # Auth-related APIs
94
96
  │ └── index.ts
95
- └── index.ts # 入口文件
97
+ └── index.ts # Entry file
96
98
  ```
97
99
 
98
- ### 不分组
100
+ ### Not Grouped
99
101
 
100
102
  ```
101
103
  src/api/
102
- ├── types.ts # 数据类型定义
103
- ├── api.ts # 所有 API 接口
104
- └── index.ts # 入口文件
104
+ ├── types.ts # Data type definitions
105
+ ├── api.ts # All API interfaces
106
+ └── index.ts # Entry file
105
107
  ```
106
108
 
107
- ## 💡 使用示例
109
+ ## 💡 Usage Examples
108
110
 
109
- ### 生成的类型定义
111
+ ### Generated Type Definitions
110
112
 
111
113
  ```typescript
112
114
  // types.ts
113
115
  export interface LoginDto {
114
- /** 账号 */
116
+ /** Account */
115
117
  account: string;
116
- /** 密码 */
118
+ /** Password */
117
119
  password: string;
118
120
  }
119
121
 
120
122
  export interface UserInfo {
121
- /** 用户ID */
123
+ /** User ID */
122
124
  id: string;
123
- /** 用户名 */
125
+ /** Username */
124
126
  username: string;
125
127
  }
126
128
  ```
127
129
 
128
- ### 生成的 API 接口
130
+ ### Generated API Interfaces
129
131
 
130
132
  ```typescript
131
133
  // authController/index.ts
@@ -133,9 +135,9 @@ import { request } from '@/utils/request';
133
135
  import type { LoginDto, LoginRespDto } from '../types';
134
136
 
135
137
  /**
136
- * 登录
137
- * @param data 登录参数
138
- * @param config 可选的请求配置
138
+ * Login
139
+ * @param data Login parameters
140
+ * @param config Optional request configuration
139
141
  */
140
142
  export const authControllerLoginPost = (data: LoginDto, config?: any) => {
141
143
  return request.post<LoginRespDto>({
@@ -146,25 +148,25 @@ export const authControllerLoginPost = (data: LoginDto, config?: any) => {
146
148
  };
147
149
  ```
148
150
 
149
- ## 🔧 CLI 命令
151
+ ## 🔧 CLI Commands
150
152
 
151
153
  ```bash
152
- # 初始化配置文件
154
+ # Initialize configuration file
153
155
  npx swagger2api-v3 init [--force]
154
156
 
155
- # 生成接口代码
157
+ # Generate interface code
156
158
  npx swagger2api-v3 generate [--config <path>]
157
159
 
158
- # 验证配置文件
160
+ # Validate configuration file
159
161
  npx swagger2api-v3 validate [--config <path>]
160
162
 
161
- # 查看帮助
163
+ # Show help
162
164
  npx swagger2api-v3 --help
163
165
  ```
164
166
 
165
- ## 📝 NPM 脚本
167
+ ## 📝 NPM Scripts
166
168
 
167
- `package.json` 中添加:
169
+ Add to `package.json`:
168
170
 
169
171
  ```json
170
172
  {
@@ -176,22 +178,22 @@ npx swagger2api-v3 --help
176
178
  }
177
179
  ```
178
180
 
179
- ## 🎨 代码格式化
181
+ ## 🎨 Code Formatting
180
182
 
181
- 支持在生成完成后自动执行格式化命令:
183
+ Support automatic execution of formatting commands after generation:
182
184
 
183
185
  ```javascript
184
- // 配置文件中
186
+ // In configuration file
185
187
  const config = {
186
- // ... 其他配置
187
- lint: 'prettier --write' // 'eslint --fix'
188
+ // ... other configurations
189
+ lint: 'prettier --write' // or 'eslint --fix', etc.
188
190
  };
189
191
  ```
190
192
 
191
- ## 🤝 贡献
193
+ ## 🤝 Contributing
192
194
 
193
- 欢迎提交 Issue Pull Request!
195
+ Issues and Pull Requests are welcome!
194
196
 
195
- ## 📄 许可证
197
+ ## 📄 License
196
198
 
197
199
  MIT License
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "swagger2api-v3",
3
- "version": "1.0.8",
4
- "description": "从 Swagger/OpenAPI 文档生成 TypeScript API 接口的命令行工具",
3
+ "version": "1.0.9",
4
+ "description": "从 Swagger(OAS3.0) 文档生成 TypeScript API 接口的命令行工具",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "commonjs",