openapi-ts-request 0.13.1 → 0.13.3

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.
@@ -86,6 +86,9 @@ class ServiceGenerator {
86
86
  const tags = hookCustomFileNames(operationObject, pathKey, method);
87
87
  // 这里判断tags
88
88
  tags.forEach((tag) => {
89
+ if (!tag) {
90
+ return;
91
+ }
89
92
  const tagLowerCase = tag.toLowerCase();
90
93
  if (priorityRule === type_1.PriorityRule.include) {
91
94
  // includeTags 为空,不会匹配任何path,故跳过
@@ -697,9 +700,12 @@ class ServiceGenerator {
697
700
  const enumArray = schemaObject.enum;
698
701
  let enumStr = '';
699
702
  let enumLabelTypeStr = '';
700
- if (config_1.numberEnum.includes(schemaObject.type) || (0, util_1.isAllNumeric)(enumArray)) {
703
+ if (config_1.numberEnum.includes(schemaObject.type) || (0, util_1.isAllNumber)(enumArray)) {
701
704
  enumStr = `{${(0, lodash_1.map)(enumArray, (value) => `"NUMBER_${value}"=${Number(value)}`).join(',')}}`;
702
705
  }
706
+ else if ((0, util_1.isAllNumeric)(enumArray)) {
707
+ enumStr = `{${(0, lodash_1.map)(enumArray, (value) => `"STRING_NUMBER_${value}"="${value}"`).join(',')}}`;
708
+ }
703
709
  else {
704
710
  enumStr = `{${(0, lodash_1.map)(enumArray, (value) => `${value}="${value}"`).join(',')}}`;
705
711
  }
@@ -716,10 +722,20 @@ class ServiceGenerator {
716
722
  return `${value}:"${enumLabel}"`;
717
723
  }).join(',')}}`;
718
724
  }
725
+ else if (schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject['x-apifox-enum']) {
726
+ enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => {
727
+ var _a;
728
+ const enumLabel = (_a = (0, lodash_1.find)(schemaObject['x-apifox-enum'], (item) => item.value === value)) === null || _a === void 0 ? void 0 : _a.description;
729
+ return `${value}:"${enumLabel}"`;
730
+ }).join(',')}}`;
731
+ }
719
732
  else {
720
- if (config_1.numberEnum.includes(schemaObject.type) || (0, util_1.isAllNumeric)(enumArray)) {
733
+ if (config_1.numberEnum.includes(schemaObject.type) || (0, util_1.isAllNumber)(enumArray)) {
721
734
  enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `"NUMBER_${value}":${Number(value)}`).join(',')}}`;
722
735
  }
736
+ else if ((0, util_1.isAllNumeric)(enumArray)) {
737
+ enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `"STRING_NUMBER_${value}":"${value}"`).join(',')}}`;
738
+ }
723
739
  else {
724
740
  enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `${value}:"${value}"`).join(',')}}`;
725
741
  }
@@ -20,3 +20,4 @@ export declare function isArraySchemaObject(schema: unknown): schema is ArraySch
20
20
  export declare function isBinaryArraySchemaObject(schema: unknown): schema is BinaryArraySchemaObject;
21
21
  export declare function resolveRefs(obj: OpenAPIObject, fields: string[]): unknown;
22
22
  export declare function isAllNumeric(arr: any): boolean;
23
+ export declare function isAllNumber(arr: any): boolean;
@@ -20,6 +20,7 @@ exports.isArraySchemaObject = isArraySchemaObject;
20
20
  exports.isBinaryArraySchemaObject = isBinaryArraySchemaObject;
21
21
  exports.resolveRefs = resolveRefs;
22
22
  exports.isAllNumeric = isAllNumeric;
23
+ exports.isAllNumber = isAllNumber;
23
24
  const tslib_1 = require("tslib");
24
25
  const lodash_1 = require("lodash");
25
26
  const reserved_words_1 = tslib_1.__importDefault(require("reserved-words"));
@@ -333,3 +334,7 @@ function resolveRefs(obj, fields) {
333
334
  function isAllNumeric(arr) {
334
335
  return (0, lodash_1.every)(arr, (item) => (0, lodash_1.isString)(item) && /^-?[0-9]+$/.test(item));
335
336
  }
337
+ // 检查数组每一项是否都是数字
338
+ function isAllNumber(arr) {
339
+ return (0, lodash_1.every)(arr, (item) => (0, lodash_1.isNumber)(item));
340
+ }
@@ -47,6 +47,11 @@ export declare function inferSchema(thing: ParameterObject | SchemaObject | Refe
47
47
  'x-apifox'?: {
48
48
  enumDescriptions: Record<string, string>;
49
49
  };
50
+ 'x-apifox-enum'?: {
51
+ value: string;
52
+ name: string;
53
+ description: string;
54
+ }[];
50
55
  items: import("../type").ISchemaObject;
51
56
  } | {
52
57
  type: string;
@@ -92,5 +97,10 @@ export declare function inferSchema(thing: ParameterObject | SchemaObject | Refe
92
97
  'x-apifox'?: {
93
98
  enumDescriptions: Record<string, string>;
94
99
  };
100
+ 'x-apifox-enum'?: {
101
+ value: string;
102
+ name: string;
103
+ description: string;
104
+ }[];
95
105
  };
96
106
  export declare function getRandomInt(min: number, max: number): number;
package/dist/type.d.ts CHANGED
@@ -17,6 +17,11 @@ type ICustomBaseSchemaObject = {
17
17
  'x-apifox'?: {
18
18
  enumDescriptions: Record<string, string>;
19
19
  };
20
+ 'x-apifox-enum'?: {
21
+ value: string;
22
+ name: string;
23
+ description: string;
24
+ }[];
20
25
  };
21
26
  export type ArraySchemaObject = Modify<OpenAPIV3.ArraySchemaObject, ICustomBaseSchemaObject & {
22
27
  items: ISchemaObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-request",
3
- "version": "0.13.1",
3
+ "version": "0.13.3",
4
4
  "description": "Swagger2/OpenAPI3 to TypeScript, request client, request mock service, enum, type field label, JSON Schemas",
5
5
  "engines": {
6
6
  "node": ">=18.0.0",