openapi-ts-request 1.12.1 → 1.12.2

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
@@ -225,7 +225,8 @@ openapi --i ./spec.json --o ./apis
225
225
 
226
226
  | 属性 | 必填 | 类型 | 默认值 | 说明 |
227
227
  | --- | --- | --- | --- | --- |
228
- | schemaPath | | string | - | Swagger2/OpenAPI3 地址 |
228
+ | schemaPath | 否\* | string | - | Swagger2/OpenAPI3 地址(与 apifoxConfig 互斥,两者必填其一) |
229
+ | apifoxConfig | 否\* | [Apifox Config](#Apifox-Config) | - | apifox 配置(与 schemaPath 互斥,两者必填其一) |
229
230
  | serversPath | 否 | string | './src/apis' | 运行结果文件夹路径 |
230
231
  | requestLibPath | 否 | string | 'axios' | 自定义请求方法路径,例如:'@/request'、'node-fetch' |
231
232
  | isSplitTypesByModule | 否 | boolean | false | 按模块拆分类型文件,开启后会生成:{module}.type.ts(各模块类型)、common.type.ts(公共类型)、enum.ts(枚举类型)、types.ts(统一导出) |
@@ -248,7 +249,6 @@ openapi --i ./spec.json --o ./apis
248
249
  | isGenJsonSchemas | 否 | boolean | false | 是否生成 JSON Schemas |
249
250
  | mockFolder | 否 | string | - | mock文件路径,例如:'./mocks' |
250
251
  | authorization | 否 | string | - | 文档权限凭证 |
251
- | apifoxConfig | 否 | [Apifox Config](#Apifox-Config) | - | apifox 配置 |
252
252
  | nullable | 否 | boolean | false | 使用 null 代替可选 |
253
253
  | isTranslateToEnglishTag | 否 | boolean | false | 将中文 tag 名称翻译成英文 tag 名称 |
254
254
  | isOnlyGenTypeScriptType | 否 | boolean | false | 仅生成 typescript 类型 |
package/dist/bin/cli.js CHANGED
@@ -7,6 +7,7 @@ const commander_1 = require("commander");
7
7
  const index_1 = require("../index");
8
8
  const log_1 = require("../log");
9
9
  const readConfig_1 = require("../readConfig");
10
+ const utils_1 = require("./utils");
10
11
  commander_1.program
11
12
  .option('-cfn, --configFileName <string>', 'config file name')
12
13
  .option('-cfp, --configFilePath <string>', 'config file path');
@@ -38,10 +39,7 @@ function run() {
38
39
  (0, prompts_1.intro)('🎉 欢迎使用 openapi-ts-request 生成器');
39
40
  const selected = yield (0, prompts_1.multiselect)({
40
41
  message: '请选择要生成的 service',
41
- options: configs.map((config) => ({
42
- value: config,
43
- label: config.describe || config.schemaPath,
44
- })),
42
+ options: (0, utils_1.createMultiselectOptions)(configs),
45
43
  });
46
44
  if ((0, prompts_1.isCancel)(selected)) {
47
45
  (0, prompts_1.cancel)('👋 Has cancelled');
@@ -58,7 +56,8 @@ function run() {
58
56
  const result = results[i];
59
57
  if (result.status === 'rejected') {
60
58
  const cnf = configs[i];
61
- const label = cnf.describe || cnf.schemaPath;
59
+ const label = cnf.describe ||
60
+ ('schemaPath' in cnf ? cnf.schemaPath : 'Apifox Config');
62
61
  errorMsg += `${label}${label && ':'}${result.reason}\n`;
63
62
  }
64
63
  }
@@ -10,6 +10,7 @@ const pkg = tslib_1.__importStar(require("../../package.json"));
10
10
  const index_1 = require("../index");
11
11
  const log_1 = require("../log");
12
12
  const readConfig_1 = require("../readConfig");
13
+ const utils_1 = require("./utils");
13
14
  const params = commander_1.program
14
15
  .name('openapi')
15
16
  .usage('[options]')
@@ -112,10 +113,7 @@ function run() {
112
113
  (0, prompts_1.intro)('🎉 欢迎使用 openapi-ts-request 生成器');
113
114
  const selected = yield (0, prompts_1.multiselect)({
114
115
  message: '请选择要生成的 service',
115
- options: configs.map((config) => ({
116
- value: config,
117
- label: config.describe || config.schemaPath,
118
- })),
116
+ options: (0, utils_1.createMultiselectOptions)(configs),
119
117
  });
120
118
  if ((0, prompts_1.isCancel)(selected)) {
121
119
  (0, prompts_1.cancel)('👋 Has cancelled');
@@ -132,7 +130,8 @@ function run() {
132
130
  const result = results[i];
133
131
  if (result.status === 'rejected') {
134
132
  const cnf = configs[i];
135
- const label = cnf.describe || cnf.schemaPath;
133
+ const label = cnf.describe ||
134
+ ('schemaPath' in cnf ? cnf.schemaPath : 'Apifox Config');
136
135
  errorMsg += `${label}${label && ':'}${result.reason}\n`;
137
136
  }
138
137
  }
@@ -0,0 +1,8 @@
1
+ import type { GenerateServiceProps } from '../index';
2
+ /**
3
+ * Helper function to create multiselect options with proper typing
4
+ */
5
+ export declare function createMultiselectOptions(configs: GenerateServiceProps[]): Array<{
6
+ value: GenerateServiceProps;
7
+ label: string;
8
+ }>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMultiselectOptions = createMultiselectOptions;
4
+ /**
5
+ * Helper function to create multiselect options with proper typing
6
+ */
7
+ function createMultiselectOptions(configs) {
8
+ return configs.map((config) => ({
9
+ value: config,
10
+ label: config.describe ||
11
+ ('schemaPath' in config ? config.schemaPath : 'Apifox Config'),
12
+ }));
13
+ }
package/dist/index.d.ts CHANGED
@@ -1,13 +1,9 @@
1
1
  import type { TypescriptFileType } from './generator/config';
2
2
  import type { APIDataType, ControllerType, ISchemaItem, ITypeItem } from './generator/type';
3
- import type { ComponentsObject, IPriorityRule, IReactQueryMode, OpenAPIObject, OperationObject, ReferenceObject, SchemaObject } from './type';
3
+ import type { ComponentsObject, IPriorityRule, IReactQueryMode, MutuallyExclusive, OpenAPIObject, OperationObject, ReferenceObject, SchemaObject } from './type';
4
4
  import { type GetSchemaByApifoxProps } from './type';
5
5
  export * from './generator/patchSchema';
6
- export type GenerateServiceProps = {
7
- /**
8
- * Swagger2/OpenAPI3 地址
9
- */
10
- schemaPath: string;
6
+ export type GenerateServicePropsBase = {
11
7
  /**
12
8
  * 生成的文件夹的路径
13
9
  */
@@ -113,10 +109,6 @@ export type GenerateServiceProps = {
113
109
  * 文档权限凭证
114
110
  */
115
111
  authorization?: string;
116
- /**
117
- * apifox 配置
118
- */
119
- apifoxConfig?: GetSchemaByApifoxProps;
120
112
  /**
121
113
  * 默认为false,true时使用null代替可选值
122
114
  */
@@ -291,6 +283,19 @@ export type GenerateServiceProps = {
291
283
  };
292
284
  };
293
285
  };
286
+ /**
287
+ * Swagger2/OpenAPI3 地址或 Apifox 配置,两者必须填写一个
288
+ */
289
+ export type GenerateServiceProps = GenerateServicePropsBase & MutuallyExclusive<{
290
+ /**
291
+ * Swagger2/OpenAPI3 地址
292
+ */
293
+ schemaPath: string;
294
+ /**
295
+ * apifox 配置
296
+ */
297
+ apifoxConfig: GetSchemaByApifoxProps;
298
+ }>;
294
299
  export declare function generateService({ requestLibPath, schemaPath, mockFolder, includeTags, excludeTags, includePaths, excludePaths, authorization, isTranslateToEnglishTag, priorityRule, timeout, reactQueryMode, apifoxConfig, ...rest }: GenerateServiceProps): Promise<void>;
295
300
  /**
296
301
  * Defines the configuration for openapi-ts-request.
package/dist/index.js CHANGED
@@ -13,7 +13,10 @@ function generateService(_a) {
13
13
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
14
  var { requestLibPath, schemaPath, mockFolder, includeTags, excludeTags, includePaths, excludePaths, authorization, isTranslateToEnglishTag, priorityRule = config_1.PriorityRule.include, timeout = 60000, reactQueryMode = config_1.ReactQueryMode.react, apifoxConfig } = _a, rest = tslib_1.__rest(_a, ["requestLibPath", "schemaPath", "mockFolder", "includeTags", "excludeTags", "includePaths", "excludePaths", "authorization", "isTranslateToEnglishTag", "priorityRule", "timeout", "reactQueryMode", "apifoxConfig"]);
15
15
  if (!schemaPath && !apifoxConfig) {
16
- return;
16
+ throw new Error('Either schemaPath or apifoxConfig must be provided. Please provide at least one configuration option.');
17
+ }
18
+ if (schemaPath && apifoxConfig) {
19
+ throw new Error('schemaPath and apifoxConfig cannot be provided at the same time. Please provide only one configuration option.');
17
20
  }
18
21
  let openAPI = null;
19
22
  if (apifoxConfig) {
@@ -34,7 +37,7 @@ function generateService(_a) {
34
37
  }
35
38
  }
36
39
  const requestImportStatement = (0, util_1.getImportStatement)(requestLibPath);
37
- const serviceGenerator = new serviceGenarator_1.default(Object.assign({ schemaPath, serversPath: './src/apis', requestImportStatement, enableLogging: false, priorityRule, includeTags: includeTags
40
+ const serviceGenerator = new serviceGenarator_1.default(Object.assign(Object.assign(Object.assign({}, (schemaPath ? { schemaPath } : { apifoxConfig })), { serversPath: './src/apis', requestImportStatement, enableLogging: false, priorityRule, includeTags: includeTags
38
41
  ? includeTags
39
42
  : priorityRule === config_1.PriorityRule.include ||
40
43
  priorityRule === config_1.PriorityRule.both
@@ -44,7 +47,7 @@ function generateService(_a) {
44
47
  : priorityRule === config_1.PriorityRule.include ||
45
48
  priorityRule === config_1.PriorityRule.both
46
49
  ? [/.*/g]
47
- : null, excludeTags: excludeTags ? excludeTags : null, excludePaths: excludePaths ? excludePaths : null, requestOptionsType: '{[key: string]: unknown}', namespace: 'API', isGenReactQuery: false, reactQueryMode, isGenJavaScript: false, isDisplayTypeLabel: false, isGenJsonSchemas: false, nullable: false, isOnlyGenTypeScriptType: false, isCamelCase: true, isSupportParseEnumDesc: false, full: true }, rest), openAPI);
50
+ : null, excludeTags: excludeTags ? excludeTags : null, excludePaths: excludePaths ? excludePaths : null, requestOptionsType: '{[key: string]: unknown}', namespace: 'API', isGenReactQuery: false, reactQueryMode, isGenJavaScript: false, isDisplayTypeLabel: false, isGenJsonSchemas: false, nullable: false, isOnlyGenTypeScriptType: false, isCamelCase: true, isSupportParseEnumDesc: false, full: true }), rest), openAPI);
48
51
  serviceGenerator.genFile();
49
52
  if (mockFolder) {
50
53
  (0, mockGenarator_1.mockGenerator)({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-request",
3
- "version": "1.12.1",
3
+ "version": "1.12.2",
4
4
  "description": "Swagger2/OpenAPI3/Apifox to TypeScript/JavaScript, request client(support any client), request mock service, enum and enum translation, react-query/vue-query, type field label, JSON Schemas",
5
5
  "engines": {
6
6
  "node": ">=18.0.0",
@@ -96,6 +96,6 @@
96
96
  "lint": "eslint ./src --report-unused-disable-directives --max-warnings=0",
97
97
  "lint:fix": "eslint ./src --report-unused-disable-directives --max-warnings=0 --fix",
98
98
  "test:unit": "vitest",
99
- "openapi-ts-request": "openapi-ts"
99
+ "openapi-ts-request": "openapi"
100
100
  }
101
101
  }