swagger2api-v3 1.0.3 → 1.0.4

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.
package/dist/cli/index.js CHANGED
@@ -115,7 +115,7 @@ program
115
115
  */
116
116
  const config = {
117
117
  // Swagger JSON 文件路径或 URL
118
- input: 'https://petstore.swagger.io/v2/swagger.json',
118
+ input: 'http://localhost:3000/admin/docs/json',
119
119
 
120
120
  // 输出目录
121
121
  output: './src/api',
@@ -61,7 +61,13 @@ class SwaggerParser {
61
61
  }
62
62
  }
63
63
  // 生成函数名
64
- const functionName = operation.operationId || (0, utils_1.pathToFunctionName)(method, path);
64
+ let functionName = operation.operationId || (0, utils_1.pathToFunctionName)(method, path);
65
+ // 如果使用了operationId,需要手动添加HTTP方法后缀
66
+ if (operation.operationId) {
67
+ // 将HTTP方法转换为首字母大写的形式并添加到末尾
68
+ const methodSuffix = method.charAt(0).toUpperCase() + method.slice(1).toLowerCase();
69
+ functionName = functionName + methodSuffix;
70
+ }
65
71
  // 获取响应类型
66
72
  const responseType = (0, utils_1.getResponseType)(operation.responses);
67
73
  // 获取请求体类型
@@ -66,19 +66,20 @@ function pathToFunctionName(method, path) {
66
66
  const cleanPath = path.replace(/\{([^}]+)\}/g, '$1');
67
67
  // 分割路径并过滤空字符串
68
68
  const segments = cleanPath.split('/').filter(segment => segment.length > 0);
69
- // 将方法名添加到开头
70
- const parts = [method.toLowerCase(), ...segments];
71
- // 转换为小驼峰命名
72
- return parts
73
- .map((part, index) => {
69
+ // 将路径段转换为驼峰命名
70
+ const pathParts = segments.map((part, index) => {
74
71
  // 移除特殊字符并转换为小驼峰
75
72
  const cleanPart = part.replace(/[^a-zA-Z0-9]/g, '');
76
73
  if (index === 0) {
77
74
  return cleanPart.toLowerCase();
78
75
  }
79
76
  return cleanPart.charAt(0).toUpperCase() + cleanPart.slice(1).toLowerCase();
80
- })
81
- .join('');
77
+ });
78
+ // 将HTTP方法转换为首字母大写的形式并添加到末尾
79
+ const methodSuffix = method.charAt(0).toUpperCase() + method.slice(1).toLowerCase();
80
+ // 组合路径名称和方法名称
81
+ const baseName = pathParts.join('');
82
+ return baseName + methodSuffix;
82
83
  }
83
84
  /**
84
85
  * 将字符串转换为kebab-case
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger2api-v3",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "从 Swagger/OpenAPI 文档生成 TypeScript API 接口的命令行工具",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",