openapi-ts-request 1.5.0 → 1.5.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.
@@ -245,10 +245,11 @@ class ServiceGenerator {
245
245
  (0, log_1.default)('✅ 成功生成 api 文件目录-> ', this.config.serversPath);
246
246
  }
247
247
  getInterfaceTPConfigs() {
248
- var _a, _b;
248
+ var _a, _b, _c;
249
249
  const schemas = (_a = this.openAPIData.components) === null || _a === void 0 ? void 0 : _a.schemas;
250
250
  const lastTypes = this.interfaceTPConfigs;
251
251
  const includeTags = ((_b = this.config) === null || _b === void 0 ? void 0 : _b.includeTags) || [];
252
+ const includePaths = ((_c = this.config) === null || _c === void 0 ? void 0 : _c.includePaths) || [];
252
253
  // 强行替换掉请求参数params的类型,生成方法对应的 xxxxParams 类型
253
254
  (0, lodash_1.keys)(this.openAPIData.paths).forEach((pathKey) => {
254
255
  const pathItem = this.openAPIData.paths[pathKey];
@@ -260,11 +261,14 @@ class ServiceGenerator {
260
261
  return;
261
262
  }
262
263
  const tags = hookCustomFileNames(operationObject, pathKey, method);
263
- if ((0, lodash_1.isEmpty)(includeTags) || (!(0, lodash_1.isEmpty)(includeTags) && (0, lodash_1.isEmpty)(tags))) {
264
+ if ((0, lodash_1.isEmpty)(includeTags) ||
265
+ (!(0, lodash_1.isEmpty)(includeTags) && (0, lodash_1.isEmpty)(tags)) ||
266
+ (0, lodash_1.isEmpty)(includePaths)) {
264
267
  return;
265
268
  }
266
269
  const flag = this.validateRegexp((0, lodash_1.filter)((0, lodash_1.map)(tags, (tag) => (tag === null || tag === void 0 ? void 0 : tag.toLowerCase) ? tag.toLowerCase() : undefined), (tag) => !!tag), includeTags);
267
- if (!flag) {
270
+ const pathFlag = this.validateRegexp(pathKey, includePaths);
271
+ if (!flag || !pathFlag) {
268
272
  return;
269
273
  }
270
274
  // 筛选出 pathItem 包含的 $ref 对应的schema
@@ -792,7 +796,7 @@ class ServiceGenerator {
792
796
  enumStr = `{${(0, lodash_1.map)(enumArray, (value) => `"STRING_NUMBER_${value}"="${value}"`).join(',')}}`;
793
797
  }
794
798
  else {
795
- enumStr = `{${(0, lodash_1.map)(enumArray, (value) => `${value}="${value}"`).join(',')}}`;
799
+ enumStr = `{${(0, lodash_1.map)(enumArray, (value) => `"${value}"="${value}"`).join(',')}}`;
796
800
  }
797
801
  // 翻译枚举
798
802
  if (schemaObject['x-enum-varnames'] && schemaObject['x-enum-comments']) {
@@ -831,7 +835,7 @@ class ServiceGenerator {
831
835
  enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `"${value}":"STRING_NUMBER_${value}"`).join(',')}}`;
832
836
  }
833
837
  else {
834
- enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `${value}:"${value}"`).join(',')}}`;
838
+ enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `"${value}":"${value}"`).join(',')}}`;
835
839
  }
836
840
  }
837
841
  return {
package/dist/index.d.ts CHANGED
@@ -206,4 +206,4 @@ export type GenerateServiceProps = {
206
206
  };
207
207
  };
208
208
  };
209
- export declare function generateService({ requestLibPath, schemaPath, mockFolder, includeTags, excludeTags, authorization, isTranslateToEnglishTag, priorityRule, timeout, reactQueryMode, apifoxConfig, ...rest }: GenerateServiceProps): Promise<void>;
209
+ export declare function generateService({ requestLibPath, schemaPath, mockFolder, includeTags, excludeTags, includePaths, excludePaths, authorization, isTranslateToEnglishTag, priorityRule, timeout, reactQueryMode, apifoxConfig, ...rest }: GenerateServiceProps): Promise<void>;
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ const util_1 = require("./util");
11
11
  tslib_1.__exportStar(require("./generator/patchSchema"), exports);
12
12
  function generateService(_a) {
13
13
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
- var { requestLibPath, schemaPath, mockFolder, includeTags, excludeTags, 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", "authorization", "isTranslateToEnglishTag", "priorityRule", "timeout", "reactQueryMode", "apifoxConfig"]);
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
16
  return;
17
17
  }
@@ -31,10 +31,18 @@ function generateService(_a) {
31
31
  const requestImportStatement = (0, util_1.getImportStatement)(requestLibPath);
32
32
  const serviceGenerator = new serviceGenarator_1.default(Object.assign({ schemaPath, serversPath: './src/apis', requestImportStatement, enableLogging: false, priorityRule, includeTags: includeTags
33
33
  ? (0, lodash_1.map)(includeTags, (item) => typeof item === 'string' ? item.toLowerCase() : item)
34
- : priorityRule === config_1.PriorityRule.include
34
+ : priorityRule === config_1.PriorityRule.include ||
35
+ priorityRule === config_1.PriorityRule.both
36
+ ? [/.*/g]
37
+ : null, includePaths: includePaths
38
+ ? (0, lodash_1.map)(includePaths, (item) => typeof item === 'string' ? item.toLowerCase() : item)
39
+ : priorityRule === config_1.PriorityRule.include ||
40
+ priorityRule === config_1.PriorityRule.both
35
41
  ? [/.*/g]
36
42
  : null, excludeTags: excludeTags
37
43
  ? (0, lodash_1.map)(excludeTags, (item) => typeof item === 'string' ? item.toLowerCase() : item)
44
+ : null, excludePaths: excludePaths
45
+ ? (0, lodash_1.map)(excludePaths, (item) => typeof item === 'string' ? item.toLowerCase() : item)
38
46
  : 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);
39
47
  serviceGenerator.genFile();
40
48
  if (mockFolder) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-request",
3
- "version": "1.5.0",
3
+ "version": "1.5.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",
@@ -24,7 +24,7 @@
24
24
  "prettier.config.cjs"
25
25
  ],
26
26
  "dependencies": {
27
- "@prettier/sync": "^0.5.2",
27
+ "@prettier/sync": "^0.6.1",
28
28
  "@trivago/prettier-plugin-sort-imports": "^5.2.1",
29
29
  "axios": "^1.7.2",
30
30
  "bing-translate-api": "^4.0.2",
@@ -66,7 +66,7 @@
66
66
  "@typescript-eslint/parser": "^7.9.0",
67
67
  "eslint": "^8.57.1",
68
68
  "husky": "^9.0.11",
69
- "lint-staged": "^15.3.0",
69
+ "lint-staged": "^16.0.0",
70
70
  "openapi-types": "^12.1.3",
71
71
  "ts-node": "^10.9.2",
72
72
  "typescript": "5.8.3"