yapi-apifox-to-typescript 4.1.2 → 4.2.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.
- package/CHANGELOG.md +47 -0
- package/lib/cjs/ApifoxToYApiData.js +393 -265
- package/lib/cjs/Generator.js +24 -11
- package/lib/cjs/utils.js +4 -0
- package/lib/esm/ApifoxToYApiData.js +392 -265
- package/lib/esm/Generator.js +24 -11
- package/lib/esm/index.d.ts +26 -0
- package/lib/esm/utils.js +4 -0
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _createForOfIteratorHelperLoose from "@babel/runtime/helpers/esm/createForOfIteratorHelperLoose";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
5
|
import axios from 'axios';
|
|
5
6
|
import { RequestBodyType, RequestFormItemType, RequestParamType, RequestQueryType, Required, ResponseBodyType } from './types';
|
|
6
7
|
import { getFilteredCat } from './utils';
|
|
7
8
|
export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
8
9
|
function ApifoxToYApiData(options) {
|
|
9
|
-
this.
|
|
10
|
-
this.folders = void 0;
|
|
10
|
+
this.openApiDoc = null;
|
|
11
11
|
this.options = void 0;
|
|
12
12
|
this.project = {
|
|
13
13
|
_id: 0,
|
|
@@ -22,55 +22,309 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
22
22
|
}]
|
|
23
23
|
};
|
|
24
24
|
this.schemas = {};
|
|
25
|
-
this.
|
|
25
|
+
this.interfaceIdCounter = 0;
|
|
26
26
|
this.options = options;
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
29
|
-
* http-api-tree 这个接口拿到所有的folder(category)
|
|
30
|
-
* data-schemas 这个接口拿到所用通用的schema
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
28
|
|
|
34
29
|
var _proto = ApifoxToYApiData.prototype;
|
|
35
30
|
|
|
36
|
-
_proto.
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
_proto.resolveRef = function resolveRef(ref) {
|
|
32
|
+
if (!ref.startsWith('#/components/schemas/')) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var schemaName = ref.replace('#/components/schemas/', '');
|
|
37
|
+
return this.schemas[schemaName] || null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
_proto.resolveSchema = function resolveSchema(schema) {
|
|
41
|
+
if (!schema) return undefined;
|
|
42
|
+
|
|
43
|
+
if (schema.$ref) {
|
|
44
|
+
return this.resolveRef(schema.$ref) || schema;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return schema;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
_proto.getSchemaType = function getSchemaType(schema) {
|
|
51
|
+
if (!schema) return 'string';
|
|
52
|
+
var resolved = this.resolveSchema(schema);
|
|
53
|
+
if (!resolved) return 'string';
|
|
54
|
+
return resolved.type || 'string';
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
_proto.convertParametersToReqParams = function convertParametersToReqParams(parameters, type) {
|
|
58
|
+
var _this = this;
|
|
59
|
+
|
|
60
|
+
if (parameters === void 0) {
|
|
61
|
+
parameters = [];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (type === 'path') {
|
|
65
|
+
return parameters.filter(function (p) {
|
|
66
|
+
return p.in === 'path';
|
|
67
|
+
}).map(function (p) {
|
|
68
|
+
return {
|
|
69
|
+
name: p.name,
|
|
70
|
+
desc: p.description || '',
|
|
71
|
+
example: p.example || '',
|
|
72
|
+
required: p.required ? Required.true : Required.false,
|
|
73
|
+
type: _this.getSchemaType(p.schema) === 'string' ? RequestParamType.string : RequestParamType.number
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return parameters.filter(function (p) {
|
|
79
|
+
return p.in === 'query';
|
|
80
|
+
}).map(function (p) {
|
|
81
|
+
return {
|
|
82
|
+
name: p.name,
|
|
83
|
+
desc: p.description || '',
|
|
84
|
+
example: p.example || '',
|
|
85
|
+
required: p.required ? Required.true : Required.false,
|
|
86
|
+
type: _this.getSchemaType(p.schema) === 'string' ? RequestQueryType.string : RequestQueryType.number
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
_proto.convertRequestBody = function convertRequestBody(requestBody) {
|
|
92
|
+
if (!(requestBody != null && requestBody.content)) {
|
|
93
|
+
return {
|
|
94
|
+
req_body_type: RequestBodyType.none,
|
|
95
|
+
req_body_is_json_schema: false,
|
|
96
|
+
req_body_form: [],
|
|
97
|
+
req_body_other: '',
|
|
98
|
+
contentType: ''
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var contentTypes = Object.keys(requestBody.content);
|
|
103
|
+
var jsonContentType = contentTypes.find(function (ct) {
|
|
104
|
+
return ct.includes('application/json');
|
|
105
|
+
});
|
|
106
|
+
var formContentType = contentTypes.find(function (ct) {
|
|
107
|
+
return ct.includes('application/x-www-form-urlencoded') || ct.includes('multipart/form-data');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
if (jsonContentType) {
|
|
111
|
+
var schema = requestBody.content[jsonContentType].schema;
|
|
112
|
+
return {
|
|
113
|
+
req_body_type: RequestBodyType.json,
|
|
114
|
+
req_body_is_json_schema: true,
|
|
115
|
+
req_body_form: [],
|
|
116
|
+
req_body_other: schema ? JSON.stringify(this.normalizeSchema(schema)) : '',
|
|
117
|
+
contentType: jsonContentType
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (formContentType) {
|
|
122
|
+
var _schema = requestBody.content[formContentType].schema;
|
|
123
|
+
var resolvedSchema = this.resolveSchema(_schema);
|
|
124
|
+
var formItems = [];
|
|
125
|
+
|
|
126
|
+
if (resolvedSchema != null && resolvedSchema.properties) {
|
|
127
|
+
var requiredFields = resolvedSchema.required || [];
|
|
128
|
+
|
|
129
|
+
for (var _i = 0, _Object$entries = Object.entries(resolvedSchema.properties); _i < _Object$entries.length; _i++) {
|
|
130
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
131
|
+
name = _Object$entries$_i[0],
|
|
132
|
+
prop = _Object$entries$_i[1];
|
|
133
|
+
var resolvedProp = this.resolveSchema(prop);
|
|
134
|
+
formItems.push({
|
|
135
|
+
name: name,
|
|
136
|
+
type: (resolvedProp == null ? void 0 : resolvedProp.type) === 'file' || (resolvedProp == null ? void 0 : resolvedProp.format) === 'binary' ? RequestFormItemType.file : RequestFormItemType.text,
|
|
137
|
+
desc: (resolvedProp == null ? void 0 : resolvedProp.description) || '',
|
|
138
|
+
example: (resolvedProp == null ? void 0 : resolvedProp.example) || '',
|
|
139
|
+
required: requiredFields.includes(name) ? Required.true : Required.false
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
req_body_type: RequestBodyType.form,
|
|
146
|
+
req_body_is_json_schema: false,
|
|
147
|
+
req_body_form: formItems,
|
|
148
|
+
req_body_other: '',
|
|
149
|
+
contentType: formContentType
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
req_body_type: RequestBodyType.raw,
|
|
155
|
+
req_body_is_json_schema: false,
|
|
156
|
+
req_body_form: [],
|
|
157
|
+
req_body_other: '',
|
|
158
|
+
contentType: contentTypes[0] || ''
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
_proto.normalizeSchema = function normalizeSchema(schema) {
|
|
163
|
+
var result = _extends({}, schema);
|
|
164
|
+
|
|
165
|
+
if (schema.$ref) {
|
|
166
|
+
var resolved = this.resolveRef(schema.$ref);
|
|
167
|
+
|
|
168
|
+
if (resolved) {
|
|
169
|
+
return this.normalizeSchema(resolved);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (schema.properties) {
|
|
174
|
+
result.properties = {};
|
|
175
|
+
|
|
176
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(schema.properties); _i2 < _Object$entries2.length; _i2++) {
|
|
177
|
+
var _Object$entries2$_i = _Object$entries2[_i2],
|
|
178
|
+
key = _Object$entries2$_i[0],
|
|
179
|
+
_value = _Object$entries2$_i[1];
|
|
180
|
+
|
|
181
|
+
if (_value) {
|
|
182
|
+
result.properties[key] = this.normalizeSchema(_value);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (schema.items) {
|
|
188
|
+
result.items = this.normalizeSchema(schema.items);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
delete result.$ref;
|
|
192
|
+
return result;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
_proto.convertResponse = function convertResponse(responses) {
|
|
196
|
+
if (responses === void 0) {
|
|
197
|
+
responses = {};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
var successResponse = responses['200'] || responses['201'] || responses['204'];
|
|
201
|
+
|
|
202
|
+
if (!(successResponse != null && successResponse.content)) {
|
|
203
|
+
return {
|
|
204
|
+
res_body_type: ResponseBodyType.json,
|
|
205
|
+
res_body_is_json_schema: false,
|
|
206
|
+
res_body: ''
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
var jsonContent = successResponse.content['application/json'];
|
|
211
|
+
|
|
212
|
+
if (jsonContent != null && jsonContent.schema) {
|
|
213
|
+
return {
|
|
214
|
+
res_body_type: ResponseBodyType.json,
|
|
215
|
+
res_body_is_json_schema: true,
|
|
216
|
+
res_body: JSON.stringify(this.normalizeSchema(jsonContent.schema))
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
res_body_type: ResponseBodyType.json,
|
|
222
|
+
res_body_is_json_schema: false,
|
|
223
|
+
res_body: ''
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
_proto.generateInterfaceId = function generateInterfaceId() {
|
|
228
|
+
this.interfaceIdCounter += 1;
|
|
229
|
+
return this.interfaceIdCounter;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
_proto.convertOperationToInterface = function convertOperationToInterface(path, method, operation, categoryName, categoryId) {
|
|
233
|
+
var parameters = operation.parameters || [];
|
|
234
|
+
var pathParams = this.convertParametersToReqParams(parameters, 'path');
|
|
235
|
+
var queryParams = this.convertParametersToReqParams(parameters, 'query'); // const headerParams = parameters.filter(p => p.in === 'header')
|
|
236
|
+
|
|
237
|
+
var reqHeaders = [];
|
|
238
|
+
var requestBodyInfo = this.convertRequestBody(operation.requestBody);
|
|
239
|
+
|
|
240
|
+
if (requestBodyInfo.contentType) {
|
|
241
|
+
reqHeaders.push({
|
|
242
|
+
name: 'Content-Type',
|
|
243
|
+
value: requestBodyInfo.contentType,
|
|
244
|
+
desc: '',
|
|
245
|
+
example: '',
|
|
246
|
+
required: Required.true
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
var responseInfo = this.convertResponse(operation.responses);
|
|
251
|
+
return {
|
|
252
|
+
_id: this.generateInterfaceId(),
|
|
253
|
+
_category: {
|
|
254
|
+
_id: categoryId,
|
|
255
|
+
_url: '',
|
|
256
|
+
name: categoryName,
|
|
257
|
+
desc: '',
|
|
258
|
+
add_time: 0,
|
|
259
|
+
up_time: 0
|
|
260
|
+
},
|
|
261
|
+
_project: _extends({}, this.project),
|
|
262
|
+
_url: '',
|
|
263
|
+
title: operation.summary || path,
|
|
264
|
+
status: operation.deprecated ? 'undone' : 'done',
|
|
265
|
+
markdown: operation.description || '',
|
|
266
|
+
path: path,
|
|
267
|
+
method: method.toUpperCase(),
|
|
268
|
+
project_id: this.options.projectId,
|
|
269
|
+
catid: categoryId,
|
|
270
|
+
tag: operation.tags || [],
|
|
271
|
+
req_headers: reqHeaders,
|
|
272
|
+
req_params: pathParams,
|
|
273
|
+
req_query: queryParams,
|
|
274
|
+
req_body_type: requestBodyInfo.req_body_type,
|
|
275
|
+
req_body_is_json_schema: requestBodyInfo.req_body_is_json_schema,
|
|
276
|
+
req_body_form: requestBodyInfo.req_body_form,
|
|
277
|
+
req_body_other: requestBodyInfo.req_body_other,
|
|
278
|
+
res_body_type: responseInfo.res_body_type,
|
|
279
|
+
res_body_is_json_schema: responseInfo.res_body_is_json_schema,
|
|
280
|
+
res_body: responseInfo.res_body,
|
|
281
|
+
add_time: Math.floor(Date.now() / 1000),
|
|
282
|
+
up_time: Math.floor(Date.now() / 1000),
|
|
283
|
+
uid: 0
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
_proto.getProjectInfo = /*#__PURE__*/function () {
|
|
39
288
|
var _getProjectInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
40
|
-
var _this
|
|
289
|
+
var _this$options$addFold, _this$options$oasVers, _this$options$exportF, _this$openApiDoc, _this$openApiDoc$comp, _this$openApiDoc2, _this$openApiDoc2$inf, _this$openApiDoc3, _this$openApiDoc3$inf;
|
|
41
290
|
|
|
42
|
-
var
|
|
291
|
+
var baseUrl, response;
|
|
43
292
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
44
293
|
while (1) {
|
|
45
294
|
switch (_context.prev = _context.next) {
|
|
46
295
|
case 0:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
_this.
|
|
296
|
+
baseUrl = this.options.serverUrl.replace(/\/$/, '');
|
|
297
|
+
_context.next = 3;
|
|
298
|
+
return axios.post(baseUrl + "/v1/projects/" + this.options.projectId + "/export-openapi?locale=zh-CN", {
|
|
299
|
+
scope: {
|
|
300
|
+
type: 'ALL',
|
|
301
|
+
excludedByTags: []
|
|
302
|
+
},
|
|
303
|
+
options: {
|
|
304
|
+
includeApifoxExtensionProperties: false,
|
|
305
|
+
addFoldersToTags: (_this$options$addFold = this.options.addFoldersToTags) != null ? _this$options$addFold : true
|
|
306
|
+
},
|
|
307
|
+
oasVersion: (_this$options$oasVers = this.options.oasVersion) != null ? _this$options$oasVers : '3.0',
|
|
308
|
+
exportFormat: (_this$options$exportF = this.options.exportFormat) != null ? _this$options$exportF : 'JSON'
|
|
309
|
+
}, {
|
|
310
|
+
headers: {
|
|
311
|
+
'Authorization': "Bearer " + this.options.token,
|
|
312
|
+
'X-Apifox-Api-Version': '2024-03-28',
|
|
313
|
+
'Content-Type': 'application/json'
|
|
314
|
+
}
|
|
60
315
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
this.project._id = schemas.data.data[0].projectId;
|
|
316
|
+
|
|
317
|
+
case 3:
|
|
318
|
+
response = _context.sent;
|
|
319
|
+
this.openApiDoc = response.data;
|
|
320
|
+
|
|
321
|
+
if ((_this$openApiDoc = this.openApiDoc) != null && (_this$openApiDoc$comp = _this$openApiDoc.components) != null && _this$openApiDoc$comp.schemas) {
|
|
322
|
+
this.schemas = this.openApiDoc.components.schemas;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
this.project._id = this.options.projectId;
|
|
326
|
+
this.project.name = ((_this$openApiDoc2 = this.openApiDoc) == null ? void 0 : (_this$openApiDoc2$inf = _this$openApiDoc2.info) == null ? void 0 : _this$openApiDoc2$inf.title) || 'ApifoxProject';
|
|
327
|
+
this.project.desc = ((_this$openApiDoc3 = this.openApiDoc) == null ? void 0 : (_this$openApiDoc3$inf = _this$openApiDoc3.info) == null ? void 0 : _this$openApiDoc3$inf.description) || '';
|
|
74
328
|
return _context.abrupt("return", _extends({}, this.project, {
|
|
75
329
|
cats: [],
|
|
76
330
|
getMockUrl: function getMockUrl() {
|
|
@@ -97,253 +351,126 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
97
351
|
}
|
|
98
352
|
|
|
99
353
|
return getProjectInfo;
|
|
100
|
-
}()
|
|
101
|
-
/**
|
|
102
|
-
* 根据筛选后的权限目录,对当前folder进行筛选
|
|
103
|
-
* 如果传入的cats为空,表明获取所有
|
|
104
|
-
*/
|
|
105
|
-
;
|
|
106
|
-
|
|
107
|
-
_proto.getValidCat = function getValidCat(cats, allFolders) {
|
|
108
|
-
var _this2 = this;
|
|
354
|
+
}();
|
|
109
355
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
356
|
+
_proto.getTagId = function getTagId(tagName) {
|
|
357
|
+
var hash = 0;
|
|
113
358
|
|
|
114
|
-
var
|
|
115
|
-
|
|
116
|
-
if (item.type !== 'apiDetailFolder') return;
|
|
117
|
-
if (cats.length && !cats.includes(item.folder.id)) return;
|
|
118
|
-
folders.push(item.folder.id);
|
|
359
|
+
for (var i = 0; i < tagName.length; i++) {
|
|
360
|
+
var _char = tagName.charCodeAt(i);
|
|
119
361
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* 根据传入的目录配置,返回有效的目录列表
|
|
128
|
-
*/
|
|
129
|
-
;
|
|
362
|
+
hash = (hash << 5) - hash + _char;
|
|
363
|
+
hash = hash & hash;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return Math.abs(hash);
|
|
367
|
+
};
|
|
130
368
|
|
|
131
369
|
_proto.getCats = function getCats(cats) {
|
|
132
|
-
var
|
|
370
|
+
var _this2 = this;
|
|
133
371
|
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* 通过目录的ID查找目录
|
|
138
|
-
*/
|
|
139
|
-
;
|
|
372
|
+
var categoryIds = getFilteredCat(cats, [], true);
|
|
140
373
|
|
|
141
|
-
|
|
142
|
-
|
|
374
|
+
if (categoryIds.length === 0 || categoryIds.includes(0)) {
|
|
375
|
+
var _this$openApiDoc4;
|
|
143
376
|
|
|
144
|
-
|
|
145
|
-
|
|
377
|
+
if (!((_this$openApiDoc4 = this.openApiDoc) != null && _this$openApiDoc4.tags)) return [];
|
|
378
|
+
return this.openApiDoc.tags.map(function (tag) {
|
|
379
|
+
return _this2.getTagId(tag.name);
|
|
380
|
+
});
|
|
146
381
|
}
|
|
147
382
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (folder) return;
|
|
383
|
+
return categoryIds;
|
|
384
|
+
};
|
|
151
385
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
386
|
+
_proto.getInterfaceList = /*#__PURE__*/function () {
|
|
387
|
+
var _getInterfaceList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syntheticalConfig) {
|
|
388
|
+
var _this$openApiDoc5;
|
|
156
389
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
});
|
|
161
|
-
return folder;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* 由于yapi中基本没有处理ref的方案
|
|
165
|
-
* 都是直接由具体的参数值管理,所以这里需要对所有的ref进行转换
|
|
166
|
-
*
|
|
167
|
-
* 在apifox中,对于cat来说,cat的children有可能是folder,对于folder,我们要过滤掉
|
|
168
|
-
*/
|
|
169
|
-
;
|
|
170
|
-
|
|
171
|
-
_proto.getInterfaceList =
|
|
172
|
-
/*#__PURE__*/
|
|
173
|
-
function () {
|
|
174
|
-
var _getInterfaceList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(syntheticalConfig) {
|
|
175
|
-
var _this4 = this;
|
|
176
|
-
|
|
177
|
-
var cat, transformRefToSchema;
|
|
178
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
390
|
+
var catId, interfaces, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation, operationTags, _iterator2, _step2, tag, tagId, interfaceInfo;
|
|
391
|
+
|
|
392
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
179
393
|
while (1) {
|
|
180
|
-
switch (
|
|
394
|
+
switch (_context2.prev = _context2.next) {
|
|
181
395
|
case 0:
|
|
182
|
-
|
|
183
|
-
|
|
396
|
+
if ((_this$openApiDoc5 = this.openApiDoc) != null && _this$openApiDoc5.paths) {
|
|
397
|
+
_context2.next = 2;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return _context2.abrupt("return", []);
|
|
184
402
|
|
|
185
|
-
|
|
186
|
-
|
|
403
|
+
case 2:
|
|
404
|
+
catId = syntheticalConfig.id;
|
|
405
|
+
interfaces = []; // let categoryName = ''
|
|
406
|
+
// if (this.openApiDoc.tags) {
|
|
407
|
+
// const tag = this.openApiDoc.tags.find(t => this.getTagId(t.name) === catId)
|
|
408
|
+
// categoryName = tag?.name || ''
|
|
409
|
+
// }
|
|
410
|
+
|
|
411
|
+
methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
|
|
412
|
+
_i3 = 0, _Object$entries3 = Object.entries(this.openApiDoc.paths);
|
|
413
|
+
|
|
414
|
+
case 6:
|
|
415
|
+
if (!(_i3 < _Object$entries3.length)) {
|
|
416
|
+
_context2.next = 22;
|
|
187
417
|
break;
|
|
188
418
|
}
|
|
189
419
|
|
|
190
|
-
|
|
420
|
+
_Object$entries3$_i = _Object$entries3[_i3], path = _Object$entries3$_i[0], pathItem = _Object$entries3$_i[1];
|
|
421
|
+
_iterator = _createForOfIteratorHelperLoose(methods);
|
|
191
422
|
|
|
192
|
-
case
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
// @ts-ignore
|
|
239
|
-
dataPropRef = (_dataProperties$item$ = dataProperties[item].items) == null ? void 0 : _dataProperties$item$['$ref']; // @ts-ignore
|
|
240
|
-
|
|
241
|
-
// @ts-ignore
|
|
242
|
-
if (dataProperties[item].type === 'array' && dataPropRef) {
|
|
243
|
-
// @ts-ignore
|
|
244
|
-
resultData.responses[resbodyIndex].jsonSchema.properties.data.properties[item].items = transformRefToSchema(dataPropRef);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
} // 处理request中可能存在的ref
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
// 处理request中可能存在的ref
|
|
251
|
-
if ((_resultData$requestBo = resultData.requestBody.jsonSchema) != null && _resultData$requestBo['x-apifox-refs'] && (_resultData$requestBo2 = resultData.requestBody.jsonSchema) != null && _resultData$requestBo2['x-apifox-orders']) {
|
|
252
|
-
// @ts-ignore
|
|
253
|
-
reqref = resultData.requestBody.jsonSchema['x-apifox-refs'][resultData.requestBody.jsonSchema['x-apifox-orders'][0]];
|
|
254
|
-
resultData.requestBody.jsonSchema.properties = transformRefToSchema(reqref['$ref']).properties; // @ts-ignore
|
|
255
|
-
|
|
256
|
-
// @ts-ignore
|
|
257
|
-
resultData.requestBody.jsonSchema['required'] = reqref.required;
|
|
258
|
-
delete resultData.requestBody.jsonSchema['x-apifox-refs'];
|
|
259
|
-
delete resultData.requestBody.jsonSchema['x-apifox-orders'];
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
return _context2.abrupt("return", {
|
|
263
|
-
_id: resultData.id,
|
|
264
|
-
_category: {
|
|
265
|
-
_id: syntheticalConfig.id,
|
|
266
|
-
_url: '',
|
|
267
|
-
name: cat.name,
|
|
268
|
-
desc: '',
|
|
269
|
-
add_time: 0,
|
|
270
|
-
up_time: 0,
|
|
271
|
-
list: []
|
|
272
|
-
},
|
|
273
|
-
_project: _extends({}, _this4.project),
|
|
274
|
-
_url: '',
|
|
275
|
-
title: resultData.name,
|
|
276
|
-
status: 'undone',
|
|
277
|
-
markdown: resultData.operationId,
|
|
278
|
-
path: resultData.path,
|
|
279
|
-
method: resultData.method.toUpperCase(),
|
|
280
|
-
project_id: resultData.projectId,
|
|
281
|
-
catid: syntheticalConfig.id,
|
|
282
|
-
tag: resultData.tags,
|
|
283
|
-
req_headers: resultData.requestBody.type ? [{
|
|
284
|
-
name: 'Content-Type',
|
|
285
|
-
value: resultData.requestBody.type,
|
|
286
|
-
desc: '',
|
|
287
|
-
example: '',
|
|
288
|
-
required: Required.true
|
|
289
|
-
}] : [],
|
|
290
|
-
req_params: ((_resultData$parameter = resultData.parameters.path) == null ? void 0 : _resultData$parameter.map(function (item) {
|
|
291
|
-
return {
|
|
292
|
-
name: item.name,
|
|
293
|
-
desc: item.description,
|
|
294
|
-
example: '',
|
|
295
|
-
required: item.required ? Required.true : Required.false,
|
|
296
|
-
type: item.type === 'string' ? RequestParamType.string : RequestParamType.number
|
|
297
|
-
};
|
|
298
|
-
})) || [],
|
|
299
|
-
req_query: ((_resultData$parameter2 = resultData.parameters.query) == null ? void 0 : _resultData$parameter2.map(function (item) {
|
|
300
|
-
return {
|
|
301
|
-
name: item.name,
|
|
302
|
-
desc: item.description,
|
|
303
|
-
example: '',
|
|
304
|
-
required: item.required ? Required.true : Required.false,
|
|
305
|
-
type: item.type === 'string' ? RequestQueryType.string : RequestQueryType.number
|
|
306
|
-
};
|
|
307
|
-
})) || [],
|
|
308
|
-
req_body_type: resultData.requestBody.type === 'multipart/form-data' ? RequestBodyType.form : resultData.requestBody.jsonSchema ? RequestBodyType.json : RequestBodyType.raw,
|
|
309
|
-
req_body_is_json_schema: !!resultData.requestBody.jsonSchema,
|
|
310
|
-
req_body_form: ((_resultData$requestBo3 = resultData.requestBody.parameters) == null ? void 0 : _resultData$requestBo3.map(function (item) {
|
|
311
|
-
return {
|
|
312
|
-
name: item.name,
|
|
313
|
-
desc: item.description,
|
|
314
|
-
example: item.example,
|
|
315
|
-
required: item.required ? Required.true : Required.false,
|
|
316
|
-
type: item.type === 'string' ? RequestFormItemType.text : RequestFormItemType.file
|
|
317
|
-
};
|
|
318
|
-
})) || [],
|
|
319
|
-
req_body_other: resultData.requestBody.jsonSchema ? JSON.stringify(resultData.requestBody.jsonSchema) : '',
|
|
320
|
-
res_body_type: ResponseBodyType.json,
|
|
321
|
-
res_body_is_json_schema: true,
|
|
322
|
-
res_body: JSON.stringify(resultData.responses[resbodyIndex].jsonSchema),
|
|
323
|
-
add_time: Math.floor(new Date(resultData.createdAt).getTime() / 1000),
|
|
324
|
-
up_time: Math.floor(new Date(resultData.updatedAt).getTime() / 1000),
|
|
325
|
-
uid: 0
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
case 11:
|
|
329
|
-
case "end":
|
|
330
|
-
return _context2.stop();
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}, _callee2);
|
|
334
|
-
}));
|
|
335
|
-
|
|
336
|
-
return function (_x2) {
|
|
337
|
-
return _ref.apply(this, arguments);
|
|
338
|
-
};
|
|
339
|
-
}())));
|
|
340
|
-
|
|
341
|
-
case 5:
|
|
423
|
+
case 9:
|
|
424
|
+
if ((_step = _iterator()).done) {
|
|
425
|
+
_context2.next = 19;
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
method = _step.value;
|
|
430
|
+
operation = pathItem[method];
|
|
431
|
+
|
|
432
|
+
if (operation) {
|
|
433
|
+
_context2.next = 14;
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return _context2.abrupt("continue", 17);
|
|
438
|
+
|
|
439
|
+
case 14:
|
|
440
|
+
operationTags = operation.tags || [];
|
|
441
|
+
|
|
442
|
+
if (operationTags.length === 0) {
|
|
443
|
+
operationTags.push('default');
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
for (_iterator2 = _createForOfIteratorHelperLoose(operationTags); !(_step2 = _iterator2()).done;) {
|
|
447
|
+
tag = _step2.value;
|
|
448
|
+
tagId = this.getTagId(tag);
|
|
449
|
+
|
|
450
|
+
if (tagId === catId) {
|
|
451
|
+
interfaceInfo = this.convertOperationToInterface(path, method, operation, tag, catId);
|
|
452
|
+
interfaces.push(interfaceInfo);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
case 17:
|
|
457
|
+
_context2.next = 9;
|
|
458
|
+
break;
|
|
459
|
+
|
|
460
|
+
case 19:
|
|
461
|
+
_i3++;
|
|
462
|
+
_context2.next = 6;
|
|
463
|
+
break;
|
|
464
|
+
|
|
465
|
+
case 22:
|
|
466
|
+
return _context2.abrupt("return", interfaces);
|
|
467
|
+
|
|
468
|
+
case 23:
|
|
342
469
|
case "end":
|
|
343
|
-
return
|
|
470
|
+
return _context2.stop();
|
|
344
471
|
}
|
|
345
472
|
}
|
|
346
|
-
},
|
|
473
|
+
}, _callee2, this);
|
|
347
474
|
}));
|
|
348
475
|
|
|
349
476
|
function getInterfaceList(_x) {
|