openapi-ts-request 0.8.4 → 0.10.0

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.
@@ -607,6 +607,7 @@ class ServiceGenerator {
607
607
  };
608
608
  }
609
609
  resolveEnumObject(schemaObject) {
610
+ var _a;
610
611
  const enumArray = schemaObject.enum;
611
612
  let enumStr = '';
612
613
  let enumLabelTypeStr = '';
@@ -623,6 +624,12 @@ class ServiceGenerator {
623
624
  return `${value}:"${schemaObject['x-enum-comments'][enumKey]}"`;
624
625
  }).join(',')}}`;
625
626
  }
627
+ else if ((_a = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject['x-apifox']) === null || _a === void 0 ? void 0 : _a['enumDescriptions']) {
628
+ enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => {
629
+ const enumLabel = schemaObject['x-apifox']['enumDescriptions'][value];
630
+ return `${value}:"${enumLabel}"`;
631
+ }).join(',')}}`;
632
+ }
626
633
  else {
627
634
  if (!config_1.numberEnum.includes(schemaObject.type)) {
628
635
  enumLabelTypeStr = `{${(0, lodash_1.map)(enumArray, (value) => `${value}:"${value}"`).join(',')}}`;
@@ -671,14 +678,12 @@ class ServiceGenerator {
671
678
  });
672
679
  }
673
680
  resolveRefObject(refObject) {
674
- var _a, _b;
675
681
  if (!(0, util_1.isReferenceObject)(refObject)) {
676
682
  return refObject;
677
683
  }
678
- // 测试了很多用例,很少有用例走到这里
679
684
  const refPaths = refObject.$ref.split('/');
680
685
  if (refPaths[0] === '#') {
681
- const schema = (_b = (_a = this.openAPIData.components) === null || _a === void 0 ? void 0 : _a.schemas) === null || _b === void 0 ? void 0 : _b[(0, util_1.getLastRefName)(refObject.$ref)];
686
+ const schema = (0, util_1.resolveRefs)(this.openAPIData, refPaths.slice(1));
682
687
  if (!schema) {
683
688
  throw new Error(`[GenSDK] Data Error! Notfoud: ${refObject.$ref}`);
684
689
  }
@@ -1,4 +1,4 @@
1
- import { ArraySchemaObject, BinaryArraySchemaObject, ComponentsObject, ISchemaObject, NonArraySchemaObject, OperationObject, ReferenceObject, SchemaObject } from '../type';
1
+ import { ArraySchemaObject, BinaryArraySchemaObject, ComponentsObject, ISchemaObject, NonArraySchemaObject, OpenAPIObject, OperationObject, ReferenceObject, SchemaObject } from '../type';
2
2
  import { ITypeItem } from './type';
3
3
  export declare function stripDot(str: string): string;
4
4
  export declare function resolveTypeName(typeName: string): string;
@@ -17,3 +17,4 @@ export declare function isSchemaObject(schema: unknown): schema is SchemaObject;
17
17
  export declare function isNonArraySchemaObject(schema: unknown): schema is NonArraySchemaObject;
18
18
  export declare function isArraySchemaObject(schema: unknown): schema is ArraySchemaObject;
19
19
  export declare function isBinaryArraySchemaObject(schema: unknown): schema is BinaryArraySchemaObject;
20
+ export declare function resolveRefs(obj: OpenAPIObject, fields: string[]): unknown;
@@ -17,6 +17,7 @@ exports.isSchemaObject = isSchemaObject;
17
17
  exports.isNonArraySchemaObject = isNonArraySchemaObject;
18
18
  exports.isArraySchemaObject = isArraySchemaObject;
19
19
  exports.isBinaryArraySchemaObject = isBinaryArraySchemaObject;
20
+ exports.resolveRefs = resolveRefs;
20
21
  const tslib_1 = require("tslib");
21
22
  const lodash_1 = require("lodash");
22
23
  const reserved_words_1 = tslib_1.__importDefault(require("reserved-words"));
@@ -315,3 +316,13 @@ function isBinaryArraySchemaObject(schema) {
315
316
  (((_a = schema.items) === null || _a === void 0 ? void 0 : _a.format) === 'binary' ||
316
317
  ((_b = schema.items) === null || _b === void 0 ? void 0 : _b.format) === 'base64'));
317
318
  }
319
+ function resolveRefs(obj, fields) {
320
+ return fields.reduce((acc, field) => {
321
+ if (!acc)
322
+ return;
323
+ const s = acc[decodeURIComponent(field)];
324
+ if (!s)
325
+ return;
326
+ return s;
327
+ }, obj);
328
+ }
@@ -44,6 +44,9 @@ export declare function inferSchema(thing: ParameterObject | SchemaObject | Refe
44
44
  'x-enum-comments'?: {
45
45
  [name: string]: string;
46
46
  };
47
+ 'x-apifox'?: {
48
+ enumDescriptions: Record<string, string>;
49
+ };
47
50
  items: import("../type").ISchemaObject;
48
51
  } | {
49
52
  type: string;
@@ -86,5 +89,8 @@ export declare function inferSchema(thing: ParameterObject | SchemaObject | Refe
86
89
  'x-enum-comments'?: {
87
90
  [name: string]: string;
88
91
  };
92
+ 'x-apifox'?: {
93
+ enumDescriptions: Record<string, string>;
94
+ };
89
95
  };
90
96
  export declare function getRandomInt(min: number, max: number): number;
package/dist/type.d.ts CHANGED
@@ -14,6 +14,9 @@ type ICustomBaseSchemaObject = {
14
14
  'x-enum-comments'?: {
15
15
  [name: string]: string;
16
16
  };
17
+ 'x-apifox'?: {
18
+ enumDescriptions: Record<string, string>;
19
+ };
17
20
  };
18
21
  export type ArraySchemaObject = Modify<OpenAPIV3.ArraySchemaObject, ICustomBaseSchemaObject & {
19
22
  items: ISchemaObject;
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "openapi-ts-request",
3
- "version": "0.8.4",
3
+ "version": "0.10.0",
4
4
  "description": "Swagger2/OpenAPI3 to TypeScript, request client, request mock service, enum, type field label, JSON Schemas",
5
+ "engines": {
6
+ "node": ">=18.0.0",
7
+ "pnpm": ">=9"
8
+ },
5
9
  "repository": {
6
10
  "type": "git",
7
11
  "url": "git+git@github.com:openapi-ui/openapi-ts-request.git"