openapi-ts-request 1.12.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
@@ -287,6 +287,8 @@ openapi --i ./spec.json --o ./apis
287
287
  | exportFormat | string | 指定导出的 OpenAPI 文件的格式,可以有值如 'JSON' 或 'YAML' | 'JSON' |
288
288
  | includeApifoxExtensionProperties | boolean | 指定是否包含 Apifox 的 OpenAPI 规范扩展字段 `x-apifox` | false |
289
289
  | addFoldersToTags | boolean | 指定是否在标签字段中包含接口的目录名称 | false |
290
+ | branchId | number | 分支ID | false |
291
+ | moduleId | number | 模块ID | false |
290
292
 
291
293
  ## JSON Schemas
292
294
 
@@ -1011,6 +1011,7 @@ class ServiceGenerator {
1011
1011
  return Helper.getProps({
1012
1012
  schemaObject,
1013
1013
  getType: (schema, namespace) => this.getType(schema, namespace),
1014
+ openAPIData: this.openAPIData,
1014
1015
  });
1015
1016
  }
1016
1017
  resolveParameterRef(param) {
@@ -67,6 +67,7 @@ export declare function resolveAllOfObject(params: {
67
67
  export declare function getProps(params: {
68
68
  schemaObject: SchemaObject;
69
69
  getType: (schema: SchemaObject) => string;
70
+ openAPIData?: OpenAPIObject;
70
71
  }): IPropObject[];
71
72
  /**
72
73
  * 解析参数引用
@@ -145,19 +145,36 @@ function resolveAllOfObject(params) {
145
145
  */
146
146
  function getProps(params) {
147
147
  var _a;
148
- const { schemaObject, getType } = params;
148
+ const { schemaObject, getType, openAPIData } = params;
149
149
  const requiredPropKeys = (_a = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.required) !== null && _a !== void 0 ? _a : false;
150
150
  const properties = schemaObject.properties;
151
151
  return (0, lodash_1.keys)(properties).map((propKey) => {
152
+ var _a, _b;
152
153
  const schema = ((properties === null || properties === void 0 ? void 0 : properties[propKey]) || config_2.DEFAULT_SCHEMA);
153
154
  // 剔除属性键值中的特殊符号,因为函数入参变量存在特殊符号会导致解析文件失败
154
155
  // eslint-disable-next-line no-useless-escape
155
156
  propKey = propKey.replace(/[\[|\]]/g, '');
157
+ // 获取描述信息,如果是 $ref 引用,尝试获取引用对象的描述
158
+ let desc = [schema.title, schema.description]
159
+ .filter((item) => item)
160
+ .join(' ')
161
+ .replace(config_2.lineBreakReg, '');
162
+ // 如果是 $ref 引用,尝试获取引用对象的描述
163
+ if ((0, util_1.isReferenceObject)(schema) && openAPIData) {
164
+ const refName = (0, util_1.getLastRefName)(schema.$ref);
165
+ const refSchema = (_b = (_a = openAPIData.components) === null || _a === void 0 ? void 0 : _a.schemas) === null || _b === void 0 ? void 0 : _b[refName];
166
+ if (refSchema) {
167
+ const refDesc = [refSchema.title, refSchema.description]
168
+ .filter((item) => item)
169
+ .join(' ')
170
+ .replace(config_2.lineBreakReg, '');
171
+ if (refDesc) {
172
+ desc = desc + refDesc;
173
+ }
174
+ }
175
+ }
156
176
  // 复用 schema 部分字段
157
- return Object.assign(Object.assign({}, schema), { name: propKey, type: getType(schema), desc: [schema.title, schema.description]
158
- .filter((item) => item)
159
- .join(' ')
160
- .replace(config_2.lineBreakReg, ''),
177
+ return Object.assign(Object.assign({}, schema), { name: propKey, type: getType(schema), desc: desc,
161
178
  // 如果没有 required 信息,默认全部是非必填
162
179
  required: requiredPropKeys
163
180
  ? requiredPropKeys.some((key) => key === propKey)
package/dist/type.d.ts CHANGED
@@ -96,13 +96,15 @@ export interface APIFoxBody {
96
96
  oasVersion?: '2.0' | '3.0' | '3.1';
97
97
  exportFormat?: 'JSON' | 'YAML';
98
98
  environmentIds?: string[];
99
+ branchId?: number;
100
+ moduleId?: number;
99
101
  }
100
- export interface GetSchemaByApifoxProps extends Pick<APIFoxBody, 'oasVersion' | 'exportFormat'>, Pick<APIFoxBody['options'], 'includeApifoxExtensionProperties' | 'addFoldersToTags'> {
102
+ export type GetSchemaByApifoxProps = {
101
103
  projectId: string;
102
104
  apifoxToken: string;
103
105
  locale?: string;
104
106
  apifoxVersion?: string;
105
107
  selectedTags?: string[];
106
108
  excludedByTags?: string[];
107
- }
109
+ } & Pick<APIFoxBody, 'oasVersion' | 'exportFormat' | 'branchId' | 'moduleId'> & APIFoxBody['options'];
108
110
  export {};
package/dist/util.js CHANGED
@@ -32,7 +32,7 @@ exports.getImportStatement = getImportStatement;
32
32
  * @param params.apifoxVersion {string} apifox 版本 目前固定为 2024-03-28 可通过 https://api.apifox.com/v1/versions 获取最新版本
33
33
  * @returns
34
34
  */
35
- const getSchemaByApifox = (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ projectId, locale = 'zh-CN', apifoxVersion = '2024-03-28', selectedTags, excludedByTags = [], apifoxToken, oasVersion = '3.0', exportFormat = 'JSON', includeApifoxExtensionProperties = false, addFoldersToTags = false, }) {
35
+ const getSchemaByApifox = (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ projectId, locale = 'zh-CN', apifoxVersion = '2024-03-28', selectedTags, excludedByTags = [], apifoxToken, oasVersion = '3.0', exportFormat = 'JSON', includeApifoxExtensionProperties = false, addFoldersToTags = false, branchId, moduleId, }) {
36
36
  try {
37
37
  const body = {
38
38
  scope: {
@@ -45,6 +45,12 @@ const getSchemaByApifox = (_a) => tslib_1.__awaiter(void 0, [_a], void 0, functi
45
45
  oasVersion,
46
46
  exportFormat,
47
47
  };
48
+ if (branchId !== undefined) {
49
+ body.branchId = branchId;
50
+ }
51
+ if (moduleId !== undefined) {
52
+ body.moduleId = moduleId;
53
+ }
48
54
  const tags = !(0, lodash_1.isEmpty)(selectedTags) ? selectedTags : '*';
49
55
  if (tags === '*') {
50
56
  body.scope.type = 'ALL';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-request",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
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",
@@ -4,6 +4,9 @@
4
4
  {%- if list.length > 0 %}
5
5
  {% for type in list -%}
6
6
  {%- if type.isEnum %}
7
+ {%- if type.description%}
8
+ /** {{ type.description }} */
9
+ {%- endif %}
7
10
  export enum {{ type.typeName | safe }} {{ type.type }};
8
11
 
9
12
  export type I{{ type.typeName | safe }} = keyof typeof {{ type.typeName }}
@@ -43,6 +43,9 @@
43
43
  {%- endfor %}
44
44
  {%- else %}
45
45
  {%- if type.isEnum %}
46
+ {%- if type.description%}
47
+ /** {{ type.description }} */
48
+ {%- endif %}
46
49
  export enum {{ type.typeName | safe }} {{ type.type }};
47
50
 
48
51
  export type I{{ type.typeName | safe }} = keyof typeof {{ type.typeName }}