openapi-ts-request 1.11.0 → 1.12.1

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/README.md CHANGED
@@ -187,6 +187,7 @@ $ openapi --help
187
187
  -cfn, --configFileName <string> config file name
188
188
  -cfp, --configFilePath <string> config file path
189
189
  --requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch" (default: "axios")
190
+ --isSplitTypesByModule <boolean> split types by module, generates {module}.type.ts, common.type.ts, enum.ts, types.ts (default: false)
190
191
  -f, --full <boolean> full replacement (default: true)
191
192
  --enableLogging <boolean> open the log (default: false)
192
193
  --priorityRule <string> priority rule, include/exclude/both (default: "include")
@@ -227,6 +228,7 @@ openapi --i ./spec.json --o ./apis
227
228
  | schemaPath | 是 | string | - | Swagger2/OpenAPI3 地址 |
228
229
  | serversPath | 否 | string | './src/apis' | 运行结果文件夹路径 |
229
230
  | requestLibPath | 否 | string | 'axios' | 自定义请求方法路径,例如:'@/request'、'node-fetch' |
231
+ | isSplitTypesByModule | 否 | boolean | false | 按模块拆分类型文件,开启后会生成:{module}.type.ts(各模块类型)、common.type.ts(公共类型)、enum.ts(枚举类型)、types.ts(统一导出) |
230
232
  | full | 否 | boolean | true | 是否全量替换 |
231
233
  | describe | 否 | string | - | 描述信息,在用 cli 可交互运行方式时会用到 |
232
234
  | enableLogging | 否 | boolean | false | 是否开启日志 |
@@ -285,6 +287,8 @@ openapi --i ./spec.json --o ./apis
285
287
  | exportFormat | string | 指定导出的 OpenAPI 文件的格式,可以有值如 'JSON' 或 'YAML' | 'JSON' |
286
288
  | includeApifoxExtensionProperties | boolean | 指定是否包含 Apifox 的 OpenAPI 规范扩展字段 `x-apifox` | false |
287
289
  | addFoldersToTags | boolean | 指定是否在标签字段中包含接口的目录名称 | false |
290
+ | branchId | number | 分支ID | false |
291
+ | moduleId | number | 模块ID | false |
288
292
 
289
293
  ## JSON Schemas
290
294
 
@@ -19,6 +19,7 @@ const params = commander_1.program
19
19
  .option('-cfn, --configFileName <string>', 'config file name')
20
20
  .option('-cfp, --configFilePath <string>', 'config file path')
21
21
  .option('--requestLibPath <string>', 'custom request lib path, for example: "@/request", "node-fetch" (default: "axios")')
22
+ .option('--isSplitTypesByModule <boolean>', 'split types by module, generates {module}.type.ts, common.type.ts, enum.ts, types.ts', false)
22
23
  .option('-f, --full <boolean>', 'full replacement', true)
23
24
  .option('--enableLogging <boolean>', 'open the log', false)
24
25
  .option('--priorityRule <string>', 'priority rule, include/exclude/both (default: "include")')
@@ -82,6 +83,7 @@ const baseGenerate = (_params_) => {
82
83
  isCamelCase: JSON.parse(_params_.isCamelCase) === true,
83
84
  isSupportParseEnumDesc: JSON.parse(_params_.isSupportParseEnumDesc) === true,
84
85
  supportParseEnumDescByReg: _params_.supportParseEnumDescByReg,
86
+ isSplitTypesByModule: JSON.parse(_params_.isSplitTypesByModule) === true,
85
87
  };
86
88
  return options;
87
89
  };
@@ -5,6 +5,8 @@ export declare const interfaceFileName = "types";
5
5
  export declare const displayEnumLabelFileName = "displayEnumLabel";
6
6
  export declare const displayTypeLabelFileName = "displayTypeLabel";
7
7
  export declare const schemaFileName = "schema";
8
+ export declare const enumFileName = "enum";
9
+ export declare const commonTypeFileName = "common.type";
8
10
  export declare const displayReactQueryFileName: (reactQueryMode: IReactQueryMode) => string;
9
11
  export declare enum TypescriptFileType {
10
12
  interface = "interface",
@@ -13,7 +15,10 @@ export declare enum TypescriptFileType {
13
15
  displayEnumLabel = "displayEnumLabel",
14
16
  displayTypeLabel = "displayTypeLabel",
15
17
  schema = "schema",
16
- reactQuery = "reactQuery"
18
+ reactQuery = "reactQuery",
19
+ moduleType = "moduleType",
20
+ typeIndex = "typeIndex",
21
+ enum = "enum"
17
22
  }
18
23
  export declare const DEFAULT_SCHEMA: SchemaObject;
19
24
  export declare const DEFAULT_PATH_PARAM: ParameterObject & Dictionary<unknown>;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LangType = exports.lineBreakReg = exports.numberEnum = exports.parametersIn = exports.parametersInsEnum = exports.methods = exports.DEFAULT_PATH_PARAM = exports.DEFAULT_SCHEMA = exports.TypescriptFileType = exports.displayReactQueryFileName = exports.schemaFileName = exports.displayTypeLabelFileName = exports.displayEnumLabelFileName = exports.interfaceFileName = exports.serviceEntryFileName = void 0;
3
+ exports.LangType = exports.lineBreakReg = exports.numberEnum = exports.parametersIn = exports.parametersInsEnum = exports.methods = exports.DEFAULT_PATH_PARAM = exports.DEFAULT_SCHEMA = exports.TypescriptFileType = exports.displayReactQueryFileName = exports.commonTypeFileName = exports.enumFileName = exports.schemaFileName = exports.displayTypeLabelFileName = exports.displayEnumLabelFileName = exports.interfaceFileName = exports.serviceEntryFileName = void 0;
4
4
  exports.serviceEntryFileName = 'index';
5
5
  exports.interfaceFileName = 'types';
6
6
  exports.displayEnumLabelFileName = 'displayEnumLabel';
7
7
  exports.displayTypeLabelFileName = 'displayTypeLabel';
8
8
  exports.schemaFileName = 'schema';
9
+ exports.enumFileName = 'enum';
10
+ exports.commonTypeFileName = 'common.type';
9
11
  const displayReactQueryFileName = (reactQueryMode) => {
10
12
  return {
11
13
  react: 'reactquery',
@@ -22,6 +24,9 @@ var TypescriptFileType;
22
24
  TypescriptFileType["displayTypeLabel"] = "displayTypeLabel";
23
25
  TypescriptFileType["schema"] = "schema";
24
26
  TypescriptFileType["reactQuery"] = "reactQuery";
27
+ TypescriptFileType["moduleType"] = "moduleType";
28
+ TypescriptFileType["typeIndex"] = "typeIndex";
29
+ TypescriptFileType["enum"] = "enum";
25
30
  })(TypescriptFileType || (exports.TypescriptFileType = TypescriptFileType = {}));
26
31
  exports.DEFAULT_SCHEMA = {
27
32
  type: 'object',
@@ -8,6 +8,7 @@ export default class ServiceGenerator {
8
8
  protected openAPIData: OpenAPIObject;
9
9
  protected schemaList: ISchemaItem[];
10
10
  protected interfaceTPConfigs: ITypeItem[];
11
+ protected typeModuleMap: Map<string, Set<string>>;
11
12
  constructor(config: GenerateServiceProps, openAPIData: OpenAPIObject);
12
13
  genFile(): void;
13
14
  private getInterfaceTPConfigs;
@@ -31,14 +32,6 @@ export default class ServiceGenerator {
31
32
  * @returns 多状态码响应类型定义字符串,如果没有响应则返回 null
32
33
  */
33
34
  private getResponsesType;
34
- /**
35
- * 解析响应条目,提取每个状态码对应的类型和描述信息
36
- *
37
- * @param responses OpenAPI 响应对象
38
- * @param components OpenAPI 组件对象,用于解析引用类型
39
- * @returns 响应条目数组,包含状态码、类型和描述
40
- */
41
- private parseResponseEntries;
42
35
  /**
43
36
  * 从响应内容中提取 TypeScript 类型
44
37
  * 处理不同的媒体类型和 schema 类型
@@ -71,4 +64,23 @@ export default class ServiceGenerator {
71
64
  * @param reg 规则
72
65
  */
73
66
  private matches;
67
+ /**
68
+ * 记录类型被某个模块使用
69
+ * @param typeName 类型名称
70
+ * @param moduleName 模块名称
71
+ */
72
+ private markTypeUsedByModule;
73
+ /**
74
+ * 获取模块需要导入的类型
75
+ * @param moduleTypes 模块类型列表
76
+ * @param commonTypes 公共类型列表
77
+ * @param enumTypes 枚举类型列表
78
+ * @returns 导入信息
79
+ */
80
+ private getModuleImports;
81
+ /**
82
+ * 分组类型:按模块、公共类型和枚举
83
+ * @returns 分组后的类型
84
+ */
85
+ private groupTypesByModule;
74
86
  }