echoapi-converter 0.0.45 → 0.0.46
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/dist/index.js +547 -157
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -256,65 +256,178 @@ const THUNDER_CLIENT_GRANT_TYPES = {
|
|
|
256
256
|
"authorization_code": "authorization_code",
|
|
257
257
|
"authorization_code_with_pkce": "authorization_code_with_pkce"
|
|
258
258
|
};
|
|
259
|
+
// export const CONTENT_TYPES: Record<string, string> = {
|
|
260
|
+
// none: 'none',
|
|
261
|
+
// 'form-data': 'multipart/form-data',
|
|
262
|
+
// urlencoded: 'application/x-www-form-urlencoded',
|
|
263
|
+
// json: 'application/json',
|
|
264
|
+
// xml: 'application/xml',
|
|
265
|
+
// javascript: 'application/javascript',
|
|
266
|
+
// plain: 'text/plain',
|
|
267
|
+
// html: 'text/html',
|
|
268
|
+
// };
|
|
269
|
+
const FILL_TYPES = {
|
|
270
|
+
left: '左填充',
|
|
271
|
+
right: '右填充'
|
|
272
|
+
};
|
|
273
|
+
const RULE_TYPES_ICON = {
|
|
274
|
+
1: '(,)',
|
|
275
|
+
2: '(|)',
|
|
276
|
+
3: '(;)',
|
|
277
|
+
4: '(\\t)',
|
|
278
|
+
5: '( )',
|
|
279
|
+
6: '(:)',
|
|
280
|
+
7: '(\\n)',
|
|
281
|
+
8: '(\\r)',
|
|
282
|
+
9: '(\\r\\n)',
|
|
283
|
+
};
|
|
259
284
|
|
|
260
285
|
// @ts-nocheck
|
|
261
|
-
const
|
|
262
|
-
|
|
286
|
+
const MAX_DEEP_COUNT = 10;
|
|
287
|
+
const schemaPath = (name, version) => {
|
|
288
|
+
if (version === '2.0') {
|
|
263
289
|
return `#/definitions/${name}`;
|
|
264
290
|
}
|
|
265
291
|
return `#/components/schemas/${name}`;
|
|
266
292
|
};
|
|
267
|
-
const
|
|
268
|
-
var _a, _b
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (lodash.has(
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
293
|
+
const deepModelRef = (originSchema, schemaMap, startSchema, count = 0) => {
|
|
294
|
+
var _a, _b;
|
|
295
|
+
try {
|
|
296
|
+
let deepCount = lodash.cloneDeep(count);
|
|
297
|
+
const schema = lodash.cloneDeep(originSchema);
|
|
298
|
+
if (lodash.has(schema, 'ECHOAPI_REFS')) {
|
|
299
|
+
const refsValue = schema === null || schema === void 0 ? void 0 : schema.ECHOAPI_REFS;
|
|
300
|
+
if (!lodash.isEmpty(refsValue) &&
|
|
301
|
+
Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]') {
|
|
302
|
+
const properties = Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]'
|
|
303
|
+
? schema === null || schema === void 0 ? void 0 : schema.properties
|
|
304
|
+
: {};
|
|
305
|
+
schema['properties'] = (_a = lodash.values(refsValue)) === null || _a === void 0 ? void 0 : _a.reduce((pre, item) => {
|
|
306
|
+
var _a, _b;
|
|
307
|
+
if ((item === null || item === void 0 ? void 0 : item.ref) &&
|
|
308
|
+
lodash.has(schemaMap, item === null || item === void 0 ? void 0 : item.ref) &&
|
|
309
|
+
!lodash.isEqual(startSchema || originSchema, (_a = schemaMap[item === null || item === void 0 ? void 0 : item.ref]) === null || _a === void 0 ? void 0 : _a.schema)) {
|
|
310
|
+
const mapValue = schemaMap[item === null || item === void 0 ? void 0 : item.ref];
|
|
311
|
+
if (mapValue && (mapValue === null || mapValue === void 0 ? void 0 : mapValue.name)) {
|
|
312
|
+
// 暂时没找到多ref引用的方案 先直接导出数据
|
|
313
|
+
// pre[mapValue?.name] = {
|
|
314
|
+
// $ref: mapValue?.path,
|
|
315
|
+
// };
|
|
316
|
+
let mapSchema = mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema;
|
|
317
|
+
if (lodash.has(mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema, 'APIPOST_REFS')) {
|
|
318
|
+
if (deepCount > MAX_DEEP_COUNT) {
|
|
319
|
+
mapSchema = mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
mapSchema = deepModelRef(mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema, schemaMap, startSchema || originSchema, ++deepCount);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
pre = Object.assign(Object.assign({}, pre), ((mapSchema === null || mapSchema === void 0 ? void 0 : mapSchema.properties) || {}));
|
|
326
|
+
}
|
|
327
|
+
if (lodash.isEqual(startSchema || originSchema, (_b = schemaMap[item === null || item === void 0 ? void 0 : item.ref]) === null || _b === void 0 ? void 0 : _b.schema)) {
|
|
328
|
+
pre = {};
|
|
283
329
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
330
|
+
}
|
|
331
|
+
return pre;
|
|
332
|
+
}, properties);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (lodash.has(schema, 'properties') &&
|
|
336
|
+
Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]') {
|
|
337
|
+
let properties_keys = lodash.keys(schema === null || schema === void 0 ? void 0 : schema.properties);
|
|
338
|
+
if (
|
|
339
|
+
// 优化展示顺序
|
|
340
|
+
(schema === null || schema === void 0 ? void 0 : schema.ECHOAPI_ORDERS) &&
|
|
341
|
+
lodash.isArray(schema === null || schema === void 0 ? void 0 : schema.ECHOAPI_ORDERS) &&
|
|
342
|
+
lodash.isEqual(lodash.sortBy(schema === null || schema === void 0 ? void 0 : schema.ECHOAPI_ORDERS), lodash.sortBy(lodash.keys(schema === null || schema === void 0 ? void 0 : schema.properties)))) {
|
|
343
|
+
properties_keys = schema === null || schema === void 0 ? void 0 : schema.ECHOAPI_ORDERS;
|
|
344
|
+
}
|
|
345
|
+
schema['properties'] = properties_keys === null || properties_keys === void 0 ? void 0 : properties_keys.reduce((pre, key) => {
|
|
346
|
+
if (key && !lodash.isEmpty(schema === null || schema === void 0 ? void 0 : schema.properties[key])) {
|
|
347
|
+
if (deepCount > MAX_DEEP_COUNT) {
|
|
348
|
+
pre[key] = schema === null || schema === void 0 ? void 0 : schema.properties[key];
|
|
290
349
|
}
|
|
291
350
|
else {
|
|
292
|
-
|
|
293
|
-
const hasInvPath = (_b = modelsObj === null || modelsObj === void 0 ? void 0 : modelsObj[oldRef]) === null || _b === void 0 ? void 0 : _b.modelPath;
|
|
294
|
-
let modelPath = splicedPath((_c = modelsObj === null || modelsObj === void 0 ? void 0 : modelsObj[oldRef]) === null || _c === void 0 ? void 0 : _c.modelPath, version);
|
|
295
|
-
if (lonely && hasInvPath) {
|
|
296
|
-
modelObj.$ref = modelPath;
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
refArr.forEach((item) => {
|
|
300
|
-
var _a;
|
|
301
|
-
const modelObjItem = modelsObj === null || modelsObj === void 0 ? void 0 : modelsObj[(_a = value === null || value === void 0 ? void 0 : value[item]) === null || _a === void 0 ? void 0 : _a.ref];
|
|
302
|
-
modelPath = splicedPath(modelObjItem === null || modelObjItem === void 0 ? void 0 : modelObjItem.modelPath, version);
|
|
303
|
-
modelObj.properties["$ref"] = modelPath;
|
|
304
|
-
});
|
|
305
|
-
}
|
|
351
|
+
pre[key] = deepModelRef(schema === null || schema === void 0 ? void 0 : schema.properties[key], schemaMap, startSchema || originSchema, ++deepCount);
|
|
306
352
|
}
|
|
307
353
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
354
|
+
return pre;
|
|
355
|
+
}, {});
|
|
356
|
+
}
|
|
357
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' && lodash.has(schema, 'items')) {
|
|
358
|
+
if (lodash.has(schema === null || schema === void 0 ? void 0 : schema.items, 'properties') &&
|
|
359
|
+
Object.prototype.toString.call((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.properties) === '[object Object]') {
|
|
360
|
+
if (deepCount <= MAX_DEEP_COUNT) {
|
|
361
|
+
schema.items = deepModelRef(schema === null || schema === void 0 ? void 0 : schema.items, schemaMap, startSchema || originSchema, ++deepCount);
|
|
362
|
+
}
|
|
313
363
|
}
|
|
314
364
|
}
|
|
365
|
+
// 处理数组的引用
|
|
366
|
+
schema === null || schema === void 0 ? true : delete schema.ECHOAPI_ORDERS;
|
|
367
|
+
schema === null || schema === void 0 ? true : delete schema.ECHOAPI_REFS;
|
|
368
|
+
return schema;
|
|
369
|
+
}
|
|
370
|
+
catch (err) {
|
|
371
|
+
console.log(err.message, "deepModelRef error");
|
|
372
|
+
return originSchema;
|
|
315
373
|
}
|
|
316
|
-
return result;
|
|
317
374
|
};
|
|
375
|
+
// export const deepHandleModelRef = (
|
|
376
|
+
// modelObj: any,
|
|
377
|
+
// modelsObj: any,
|
|
378
|
+
// version: string
|
|
379
|
+
// ) => {
|
|
380
|
+
// const result = modelObj;
|
|
381
|
+
// // 遍历所有属性
|
|
382
|
+
// for (const key in modelObj) {
|
|
383
|
+
// if (has(modelObj, key)) {
|
|
384
|
+
// const value = modelObj[key];
|
|
385
|
+
// // 如果属性名为 "APIPOST_REFS"
|
|
386
|
+
// if (key === "APIPOST_REFS") {
|
|
387
|
+
// const lonely =
|
|
388
|
+
// !has(modelObj, "properties") || isEmpty(modelObj.properties);
|
|
389
|
+
// if (isPlainObject(value) && !isEmpty(value)) {
|
|
390
|
+
// const refArr: any = Object.keys(value);
|
|
391
|
+
// let modelPath = "";
|
|
392
|
+
// if (refArr.length > 1) {
|
|
393
|
+
// if (!has(modelObj, "properties")) {
|
|
394
|
+
// modelObj.properties = {};
|
|
395
|
+
// }
|
|
396
|
+
// refArr.forEach((item: any) => {
|
|
397
|
+
// const modelObjItem = modelsObj?.[value?.[item]?.ref];
|
|
398
|
+
// modelPath = splicedPath(modelObjItem?.modelPath, version);
|
|
399
|
+
// modelObj.properties["$ref"] = modelPath;
|
|
400
|
+
// });
|
|
401
|
+
// } else {
|
|
402
|
+
// const oldRef = value?.[refArr[0]]?.ref;
|
|
403
|
+
// const hasInvPath = modelsObj?.[oldRef]?.modelPath;
|
|
404
|
+
// let modelPath = splicedPath(
|
|
405
|
+
// modelsObj?.[oldRef]?.modelPath,
|
|
406
|
+
// version
|
|
407
|
+
// );
|
|
408
|
+
// if (lonely && hasInvPath) {
|
|
409
|
+
// modelObj.$ref = modelPath;
|
|
410
|
+
// } else {
|
|
411
|
+
// refArr.forEach((item: any) => {
|
|
412
|
+
// const modelObjItem = modelsObj?.[value?.[item]?.ref];
|
|
413
|
+
// modelPath = splicedPath(modelObjItem?.modelPath, version);
|
|
414
|
+
// modelObj.properties["$ref"] = modelPath;
|
|
415
|
+
// });
|
|
416
|
+
// }
|
|
417
|
+
// }
|
|
418
|
+
// }
|
|
419
|
+
// }
|
|
420
|
+
// // 如果属性是一个对象,就递归查找
|
|
421
|
+
// else if (
|
|
422
|
+
// Object.prototype.toString.call(value) === "[object Object]" &&
|
|
423
|
+
// value !== null
|
|
424
|
+
// ) {
|
|
425
|
+
// modelObj[key] = deepHandleModelRef(value, modelsObj, version);
|
|
426
|
+
// }
|
|
427
|
+
// }
|
|
428
|
+
// }
|
|
429
|
+
// return result;
|
|
430
|
+
// };
|
|
318
431
|
const removeQuery = (url) => {
|
|
319
432
|
let path = url;
|
|
320
433
|
try {
|
|
@@ -405,11 +518,12 @@ const handlePathItemBodyParameters = (body, pathItem, modelsObj) => {
|
|
|
405
518
|
in: "body",
|
|
406
519
|
name: "body",
|
|
407
520
|
description: "",
|
|
408
|
-
schema: (body === null || body === void 0 ? void 0 : body.raw_schema) || {
|
|
521
|
+
schema: deepModelRef((body === null || body === void 0 ? void 0 : body.raw_schema) || {
|
|
522
|
+
type: 'object'
|
|
523
|
+
}, modelsObj),
|
|
409
524
|
type: "string",
|
|
410
525
|
example: (body === null || body === void 0 ? void 0 : body.raw) || "",
|
|
411
526
|
};
|
|
412
|
-
obj = deepHandleModelRef(obj, modelsObj, "2.0");
|
|
413
527
|
pathItem.parameters.push(obj);
|
|
414
528
|
}
|
|
415
529
|
else if (["multipart/form-data", "application/x-www-form-urlencoded"].includes(mode)) {
|
|
@@ -433,7 +547,138 @@ const handlePathItemBodyParameters = (body, pathItem, modelsObj) => {
|
|
|
433
547
|
}
|
|
434
548
|
}
|
|
435
549
|
};
|
|
436
|
-
const
|
|
550
|
+
const handleGraphqlRequestBody = (query_list, query_schema, pathItem, modelsObj) => {
|
|
551
|
+
if (lodash.isArray(query_list) && query_list.length > 0) {
|
|
552
|
+
if (!lodash.has(pathItem, "requestBody")) {
|
|
553
|
+
pathItem.requestBody = {
|
|
554
|
+
content: {},
|
|
555
|
+
'x-schema': query_schema || {}
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
query_list.forEach(m => {
|
|
559
|
+
var _a, _b, _c;
|
|
560
|
+
const mode = `x-${m === null || m === void 0 ? void 0 : m.param_id}`;
|
|
561
|
+
pathItem.requestBody.content[mode] = {
|
|
562
|
+
'x-query': (m === null || m === void 0 ? void 0 : m.query) || '',
|
|
563
|
+
'x-variables': (m === null || m === void 0 ? void 0 : m.variables) || '',
|
|
564
|
+
'x-summary': (m === null || m === void 0 ? void 0 : m.name) || '',
|
|
565
|
+
'x-response': {
|
|
566
|
+
'x-mode': ((_a = m === null || m === void 0 ? void 0 : m.response) === null || _a === void 0 ? void 0 : _a.mode) || '',
|
|
567
|
+
example: ((_b = m === null || m === void 0 ? void 0 : m.response) === null || _b === void 0 ? void 0 : _b.raw) || "",
|
|
568
|
+
schema: deepModelRef(((_c = m === null || m === void 0 ? void 0 : m.response) === null || _c === void 0 ? void 0 : _c.raw_schema) || {
|
|
569
|
+
type: "object",
|
|
570
|
+
}, modelsObj),
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
const handleSocketMethodParameterDescription = (item, mode) => {
|
|
577
|
+
let description = item === null || item === void 0 ? void 0 : item.description;
|
|
578
|
+
let rules = item === null || item === void 0 ? void 0 : item.rules;
|
|
579
|
+
if (mode == 'fixed_message') {
|
|
580
|
+
let fillTypStr = (FILL_TYPES === null || FILL_TYPES === void 0 ? void 0 : FILL_TYPES[rules === null || rules === void 0 ? void 0 : rules.fill_type]) || '';
|
|
581
|
+
return `${description}\n${fillTypStr}至长度${rules === null || rules === void 0 ? void 0 : rules.length},填充字符${rules === null || rules === void 0 ? void 0 : rules.custom}`;
|
|
582
|
+
}
|
|
583
|
+
else if (mode == 'delimiter_message') {
|
|
584
|
+
return `${description}\n结尾添加分隔符${RULE_TYPES_ICON[rules === null || rules === void 0 ? void 0 : rules.delimiter]}`;
|
|
585
|
+
}
|
|
586
|
+
return description;
|
|
587
|
+
};
|
|
588
|
+
const handleSocketMethodRequestBody = (body, pathItem) => {
|
|
589
|
+
if (lodash.isPlainObject(body) && !lodash.isEmpty(body)) {
|
|
590
|
+
if (!lodash.has(pathItem, "requestBody")) {
|
|
591
|
+
pathItem.requestBody = {
|
|
592
|
+
content: {},
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
const mode = MODE_TYPE[body === null || body === void 0 ? void 0 : body.mode];
|
|
596
|
+
const parameter = (body === null || body === void 0 ? void 0 : body.parameter) || [];
|
|
597
|
+
if (['delimiter_message', 'fixed_message'].includes(body === null || body === void 0 ? void 0 : body.mode)) {
|
|
598
|
+
pathItem.requestBody.content[body === null || body === void 0 ? void 0 : body.mode] = {
|
|
599
|
+
'x-mode': (body === null || body === void 0 ? void 0 : body.mode) || '',
|
|
600
|
+
schema: {
|
|
601
|
+
type: "object",
|
|
602
|
+
properties: parameter.reduce((lastData, item) => {
|
|
603
|
+
if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
|
|
604
|
+
item.key.length > 0 &&
|
|
605
|
+
(!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
|
|
606
|
+
lastData[item.key] = {
|
|
607
|
+
type: "string",
|
|
608
|
+
description: handleSocketMethodParameterDescription(item, body === null || body === void 0 ? void 0 : body.mode),
|
|
609
|
+
example: (item === null || item === void 0 ? void 0 : item.value) || "",
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
return lastData;
|
|
613
|
+
}, {}),
|
|
614
|
+
},
|
|
615
|
+
example: "",
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
let modeStr = MODE_TYPE[mode];
|
|
620
|
+
if (modeStr) {
|
|
621
|
+
pathItem.requestBody.content[modeStr] = {
|
|
622
|
+
'x-mode': modeStr || '',
|
|
623
|
+
schema: {
|
|
624
|
+
type: "object",
|
|
625
|
+
},
|
|
626
|
+
example: (body === null || body === void 0 ? void 0 : body.raw) || "",
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
const handleMessagePathItemrequestBody = (message, pathItem, modelsObj) => {
|
|
633
|
+
if (lodash.isArray(message) && message.length > 0) {
|
|
634
|
+
if (!lodash.has(pathItem, "requestBody")) {
|
|
635
|
+
pathItem.requestBody = {
|
|
636
|
+
content: {},
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
message.forEach(m => {
|
|
640
|
+
var _a, _b, _c, _d, _e, _f;
|
|
641
|
+
const mode = `x-${m === null || m === void 0 ? void 0 : m.param_id}`;
|
|
642
|
+
pathItem.requestBody.content[mode] = {
|
|
643
|
+
'x-mode': ((_a = m === null || m === void 0 ? void 0 : m.request) === null || _a === void 0 ? void 0 : _a.mode) || '',
|
|
644
|
+
'x-summary': (m === null || m === void 0 ? void 0 : m.name) || '',
|
|
645
|
+
schema: deepModelRef(((_b = m === null || m === void 0 ? void 0 : m.request) === null || _b === void 0 ? void 0 : _b.raw_schema) || {
|
|
646
|
+
type: "object",
|
|
647
|
+
}, modelsObj),
|
|
648
|
+
example: ((_c = m === null || m === void 0 ? void 0 : m.request) === null || _c === void 0 ? void 0 : _c.raw) || "",
|
|
649
|
+
'x-response': {
|
|
650
|
+
'x-mode': ((_d = m === null || m === void 0 ? void 0 : m.response) === null || _d === void 0 ? void 0 : _d.mode) || '',
|
|
651
|
+
example: ((_e = m === null || m === void 0 ? void 0 : m.response) === null || _e === void 0 ? void 0 : _e.raw) || "",
|
|
652
|
+
schema: deepModelRef(((_f = m === null || m === void 0 ? void 0 : m.response) === null || _f === void 0 ? void 0 : _f.raw_schema) || {
|
|
653
|
+
type: "object",
|
|
654
|
+
}, modelsObj),
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
const handlePathItemResponse = (response, modelsObj) => {
|
|
661
|
+
const temp_responses = {};
|
|
662
|
+
const example = (response === null || response === void 0 ? void 0 : response.example) || [];
|
|
663
|
+
if (lodash.isPlainObject(response)) {
|
|
664
|
+
example.forEach(({ expect, raw }) => {
|
|
665
|
+
const code = expect === null || expect === void 0 ? void 0 : expect.code;
|
|
666
|
+
if (lodash.isNumber(code) || lodash.isString(code)) {
|
|
667
|
+
temp_responses[code] = {
|
|
668
|
+
description: (expect === null || expect === void 0 ? void 0 : expect.name) || "",
|
|
669
|
+
content: {
|
|
670
|
+
[(MODE_TYPE === null || MODE_TYPE === void 0 ? void 0 : MODE_TYPE[expect === null || expect === void 0 ? void 0 : expect.content_type]) || "*/*"]: {
|
|
671
|
+
schema: deepModelRef((expect === null || expect === void 0 ? void 0 : expect.schema) || {}, modelsObj),
|
|
672
|
+
example: raw || '',
|
|
673
|
+
},
|
|
674
|
+
},
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
return temp_responses;
|
|
680
|
+
};
|
|
681
|
+
const handlePathItemRequestBody = (body, pathItem, modelsObj) => {
|
|
437
682
|
if (lodash.isPlainObject(body) && !lodash.isEmpty(body) && (body === null || body === void 0 ? void 0 : body.mode) != "none") {
|
|
438
683
|
if (!lodash.has(pathItem, "requestBody")) {
|
|
439
684
|
pathItem.requestBody = {
|
|
@@ -450,9 +695,9 @@ const handlePathItemrequestBody = (body, pathItem) => {
|
|
|
450
695
|
"text/html",
|
|
451
696
|
].includes(mode)) {
|
|
452
697
|
pathItem.requestBody.content[mode] = {
|
|
453
|
-
schema: (body === null || body === void 0 ? void 0 : body.raw_schema) || {
|
|
454
|
-
type: "
|
|
455
|
-
},
|
|
698
|
+
schema: deepModelRef((body === null || body === void 0 ? void 0 : body.raw_schema) || {
|
|
699
|
+
type: "object",
|
|
700
|
+
}, modelsObj),
|
|
456
701
|
example: (body === null || body === void 0 ? void 0 : body.raw) || "",
|
|
457
702
|
};
|
|
458
703
|
}
|
|
@@ -462,19 +707,19 @@ const handlePathItemrequestBody = (body, pathItem) => {
|
|
|
462
707
|
pathItem.requestBody.content[mode] = {
|
|
463
708
|
schema: {
|
|
464
709
|
type: "object",
|
|
710
|
+
properties: parameter.reduce((lastData, item) => {
|
|
711
|
+
if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
|
|
712
|
+
item.key.length > 0 &&
|
|
713
|
+
(!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
|
|
714
|
+
lastData[item.key] = {
|
|
715
|
+
type: "string",
|
|
716
|
+
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
717
|
+
example: (item === null || item === void 0 ? void 0 : item.value) || "",
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
return lastData;
|
|
721
|
+
}, {})
|
|
465
722
|
},
|
|
466
|
-
properties: parameter.reduce((lastData, item) => {
|
|
467
|
-
if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
|
|
468
|
-
item.key.length > 0 &&
|
|
469
|
-
(!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
|
|
470
|
-
lastData[item.key] = {
|
|
471
|
-
type: "string",
|
|
472
|
-
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
473
|
-
example: (item === null || item === void 0 ? void 0 : item.value) || "",
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
return lastData;
|
|
477
|
-
}, {}),
|
|
478
723
|
};
|
|
479
724
|
}
|
|
480
725
|
}
|
|
@@ -484,25 +729,151 @@ const handlePathItemrequestBody = (body, pathItem) => {
|
|
|
484
729
|
(pathItem === null || pathItem === void 0 ? void 0 : pathItem.requestBody) && delete pathItem.requestBody;
|
|
485
730
|
}
|
|
486
731
|
};
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
732
|
+
const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, target_type) => {
|
|
733
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
|
|
734
|
+
const path = recursiveFolderPath("", sourceObj, pid, pidName);
|
|
735
|
+
const pathItem = {
|
|
736
|
+
'x-protocol': target_type || '',
|
|
737
|
+
summary: (item === null || item === void 0 ? void 0 : item.name) || "",
|
|
738
|
+
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
739
|
+
tags: (item === null || item === void 0 ? void 0 : item.tags) || [],
|
|
740
|
+
};
|
|
741
|
+
if (lodash.isArray(item === null || item === void 0 ? void 0 : item.tags) && (item === null || item === void 0 ? void 0 : item.tags.length) > 0) {
|
|
742
|
+
pathItem['x-tags'] = item === null || item === void 0 ? void 0 : item.tags;
|
|
743
|
+
}
|
|
744
|
+
if (lodash.isString(item === null || item === void 0 ? void 0 : item.mark_id)) {
|
|
745
|
+
pathItem['x-mark-id'] = item === null || item === void 0 ? void 0 : item.mark_id;
|
|
746
|
+
}
|
|
747
|
+
if (lodash.isString(item === null || item === void 0 ? void 0 : item.updated_at)) {
|
|
748
|
+
pathItem['x-updated-at'] = item === null || item === void 0 ? void 0 : item.tags;
|
|
749
|
+
}
|
|
750
|
+
if (lodash.isString((_a = item === null || item === void 0 ? void 0 : item.updated_user) === null || _a === void 0 ? void 0 : _a.nick_name)) {
|
|
751
|
+
pathItem['x-updated-user-name'] = (_b = item === null || item === void 0 ? void 0 : item.updated_user) === null || _b === void 0 ? void 0 : _b.nick_name;
|
|
752
|
+
}
|
|
753
|
+
if (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.attribute_info) && !lodash.isEmpty(item === null || item === void 0 ? void 0 : item.attribute_info)) {
|
|
754
|
+
pathItem['x-attribute-info'] = item === null || item === void 0 ? void 0 : item.attribute_info;
|
|
755
|
+
}
|
|
756
|
+
if ((item === null || item === void 0 ? void 0 : item.is_exampled) === 1) {
|
|
757
|
+
pathItem['x-exampled'] = item === null || item === void 0 ? void 0 : item.is_exampled;
|
|
758
|
+
}
|
|
759
|
+
if (['http', 'sse'].includes(target_type)) {
|
|
760
|
+
// 处理 Query 和 Header 参数
|
|
761
|
+
handlePathItemParameters("query", ((_d = (_c = item === null || item === void 0 ? void 0 : item.request) === null || _c === void 0 ? void 0 : _c.query) === null || _d === void 0 ? void 0 : _d.parameter) || [], pathItem);
|
|
762
|
+
handlePathItemParameters("header", ((_f = (_e = item === null || item === void 0 ? void 0 : item.request) === null || _e === void 0 ? void 0 : _e.header) === null || _f === void 0 ? void 0 : _f.parameter) || [], pathItem);
|
|
763
|
+
handlePathItemParameters("cookie", ((_h = (_g = item === null || item === void 0 ? void 0 : item.request) === null || _g === void 0 ? void 0 : _g.cookie) === null || _h === void 0 ? void 0 : _h.parameter) || [], pathItem);
|
|
764
|
+
// 处理请求体参数(根据 Swagger 版本)
|
|
765
|
+
if (apiVersion === "2.0") {
|
|
766
|
+
handlePathItemBodyParameters(((_j = item === null || item === void 0 ? void 0 : item.request) === null || _j === void 0 ? void 0 : _j.body) || {}, pathItem, modelsObj);
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
handlePathItemRequestBody(((_k = item === null || item === void 0 ? void 0 : item.request) === null || _k === void 0 ? void 0 : _k.body) || {}, pathItem, modelsObj);
|
|
770
|
+
}
|
|
771
|
+
// 添加路径标签
|
|
772
|
+
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
773
|
+
pathItem.tags = [...pathItem.tags, path];
|
|
774
|
+
}
|
|
775
|
+
// 处理响应
|
|
776
|
+
pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
|
|
777
|
+
}
|
|
778
|
+
else if (['websocket2', 'socketio', 'graphql'].includes(target_type)) {
|
|
779
|
+
// 拼接description
|
|
780
|
+
if (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.config)) {
|
|
781
|
+
switch (target_type) {
|
|
782
|
+
case 'socketio':
|
|
783
|
+
pathItem.description = `${pathItem.description}
|
|
784
|
+
Over a secure connection,${((_l = item === null || item === void 0 ? void 0 : item.config) === null || _l === void 0 ? void 0 : _l.certificate_verification) == -1 ? 'Do not enable server certificate verification.' : 'Enable server certificate verification'},And use the client version ${((_m = item === null || item === void 0 ? void 0 : item.config) === null || _m === void 0 ? void 0 : _m.socket_version) || 'v4'}And the specified handshake path ${((_o = item === null || item === void 0 ? void 0 : item.config) === null || _o === void 0 ? void 0 : _o.shake_hands_path) || '/socket.io'} make a connection.`;
|
|
785
|
+
break;
|
|
786
|
+
case 'websocket2':
|
|
787
|
+
pathItem.description = `${pathItem.description}
|
|
788
|
+
Over a secure connection,${((_p = item === null || item === void 0 ? void 0 : item.config) === null || _p === void 0 ? void 0 : _p.certificate_verification) == -1 ? 'Do not enable server certificate verification.' : 'Enable server certificate verification'},${((_q = item === null || item === void 0 ? void 0 : item.config) === null || _q === void 0 ? void 0 : _q.information_size) == 0 ? 'And there is no limit to the maximum sent content that can be received。' : `And the maximum sent content allowed to be received is${((_r = item === null || item === void 0 ? void 0 : item.config) === null || _r === void 0 ? void 0 : _r.information_size) || 5}M。`}`;
|
|
789
|
+
break;
|
|
502
790
|
}
|
|
503
|
-
}
|
|
791
|
+
}
|
|
792
|
+
handlePathItemParameters("query", ((_t = (_s = item === null || item === void 0 ? void 0 : item.request) === null || _s === void 0 ? void 0 : _s.query) === null || _t === void 0 ? void 0 : _t.parameter) || [], pathItem);
|
|
793
|
+
handlePathItemParameters("header", ((_v = (_u = item === null || item === void 0 ? void 0 : item.request) === null || _u === void 0 ? void 0 : _u.header) === null || _v === void 0 ? void 0 : _v.parameter) || [], pathItem);
|
|
794
|
+
handlePathItemParameters("cookie", ((_x = (_w = item === null || item === void 0 ? void 0 : item.request) === null || _w === void 0 ? void 0 : _w.cookie) === null || _x === void 0 ? void 0 : _x.parameter) || [], pathItem);
|
|
795
|
+
if (target_type == 'socketio')
|
|
796
|
+
handlePathItemParameters("event", ((_z = (_y = item === null || item === void 0 ? void 0 : item.request) === null || _y === void 0 ? void 0 : _y.event) === null || _z === void 0 ? void 0 : _z.parameter) || [], pathItem);
|
|
797
|
+
// 处理请体
|
|
798
|
+
if (target_type == 'graphql') {
|
|
799
|
+
handleGraphqlRequestBody(((_1 = (_0 = item === null || item === void 0 ? void 0 : item.request) === null || _0 === void 0 ? void 0 : _0.body) === null || _1 === void 0 ? void 0 : _1.query_list) || [], ((_3 = (_2 = item === null || item === void 0 ? void 0 : item.request) === null || _2 === void 0 ? void 0 : _2.body) === null || _3 === void 0 ? void 0 : _3.query_schema) || {}, pathItem, modelsObj);
|
|
800
|
+
}
|
|
801
|
+
else {
|
|
802
|
+
handleMessagePathItemrequestBody((item === null || item === void 0 ? void 0 : item.message) || [], pathItem, modelsObj);
|
|
803
|
+
}
|
|
804
|
+
// 添加路径标签
|
|
805
|
+
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
806
|
+
pathItem.tags = [...pathItem.tags, path];
|
|
807
|
+
}
|
|
504
808
|
}
|
|
505
|
-
|
|
809
|
+
else if (target_type == 'socket_method') {
|
|
810
|
+
// 拼接description
|
|
811
|
+
const configs = (_4 = item === null || item === void 0 ? void 0 : item.request) === null || _4 === void 0 ? void 0 : _4.configs;
|
|
812
|
+
if (lodash.isPlainObject(configs)) {
|
|
813
|
+
let requestString = `The encoding format of the request packet is ${configs === null || configs === void 0 ? void 0 : configs.charset} ${lodash.isArray((_5 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _5 === void 0 ? void 0 : _5.request) && ((_6 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _6 === void 0 ? void 0 : _6.request.length) > 0 ?
|
|
814
|
+
(_7 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _7 === void 0 ? void 0 : _7.request.map((r, index) => {
|
|
815
|
+
var _a;
|
|
816
|
+
let str = getTcpMethodFucString(r);
|
|
817
|
+
if (index < ((_a = configs === null || configs === void 0 ? void 0 : configs.func) === null || _a === void 0 ? void 0 : _a.request.length) - 1) {
|
|
818
|
+
return str + ',';
|
|
819
|
+
}
|
|
820
|
+
return str;
|
|
821
|
+
}) : ''}`;
|
|
822
|
+
let responseString = lodash.isArray((_8 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _8 === void 0 ? void 0 : _8.response) && ((_9 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _9 === void 0 ? void 0 : _9.response.length) > 0 ? (_10 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _10 === void 0 ? void 0 : _10.response.map((r, index) => {
|
|
823
|
+
var _a;
|
|
824
|
+
let str = getTcpMethodFucString(r);
|
|
825
|
+
if (index < ((_a = configs === null || configs === void 0 ? void 0 : configs.func) === null || _a === void 0 ? void 0 : _a.request.length) - 1) {
|
|
826
|
+
return str + ',';
|
|
827
|
+
}
|
|
828
|
+
return str + '。';
|
|
829
|
+
}) : '';
|
|
830
|
+
pathItem.description = `${pathItem.description}\n${requestString}\n${responseString}`;
|
|
831
|
+
}
|
|
832
|
+
handleSocketMethodRequestBody(((_11 = item === null || item === void 0 ? void 0 : item.request) === null || _11 === void 0 ? void 0 : _11.body) || {}, pathItem);
|
|
833
|
+
// 处理响应
|
|
834
|
+
pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
|
|
835
|
+
// 添加路径标签
|
|
836
|
+
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
837
|
+
pathItem.tags = [...pathItem.tags, path];
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
else if (target_type == 'doc') {
|
|
841
|
+
// 添加路径标签
|
|
842
|
+
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
843
|
+
pathItem.tags = [...pathItem.tags, path];
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return pathItem;
|
|
847
|
+
};
|
|
848
|
+
const getTcpMethodFucString = (func) => {
|
|
849
|
+
switch (func === null || func === void 0 ? void 0 : func.id) {
|
|
850
|
+
case 'addCharToPacketEnd':
|
|
851
|
+
return `Add a newline character at the end of each request message ${func === null || func === void 0 ? void 0 : func.option}`;
|
|
852
|
+
case 'calcLengthToPacketHeader':
|
|
853
|
+
return `Calculates the content length (excluding the header) and adds it to the header (in text format, the header byte length is ${func === null || func === void 0 ? void 0 : func.option})`;
|
|
854
|
+
case 'removePacketHeader':
|
|
855
|
+
return `The response packet needs to be stripped of its header (length ${func === null || func === void 0 ? void 0 : func.option} byte)`;
|
|
856
|
+
case 'removeWrapChar':
|
|
857
|
+
return `Removes the newline character at the end of the line ${func === null || func === void 0 ? void 0 : func.option}`;
|
|
858
|
+
case 'parseXmlToJson':
|
|
859
|
+
return 'And convert the content in XML format to JSON format';
|
|
860
|
+
}
|
|
861
|
+
return '';
|
|
862
|
+
};
|
|
863
|
+
const getSocketRequestStr = (end_func) => {
|
|
864
|
+
switch (end_func === null || end_func === void 0 ? void 0 : end_func.name) {
|
|
865
|
+
case 'none':
|
|
866
|
+
return `Data received deemed complete (subcontracting is not addressed`;
|
|
867
|
+
case 'endedChar':
|
|
868
|
+
return `Packet tail with special characters ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
|
|
869
|
+
case 'endedHexChar':
|
|
870
|
+
return `Packet tail with special characters (binary message) ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
|
|
871
|
+
case 'endedHeaderByteLength':
|
|
872
|
+
return `[header + packet body] format message ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
|
|
873
|
+
case 'endedContentByteLength':
|
|
874
|
+
return `Fixed-length message ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
|
|
875
|
+
}
|
|
876
|
+
return '';
|
|
506
877
|
};
|
|
507
878
|
|
|
508
879
|
const throwResult$1 = (status, message, data = '') => {
|
|
@@ -804,7 +1175,7 @@ class ApipostToSwagger {
|
|
|
804
1175
|
this.apiToSwaggerVersion = "2.0";
|
|
805
1176
|
}
|
|
806
1177
|
handleProject() {
|
|
807
|
-
const { name, intro } = this.apiToSwaggerOrigin.project || {};
|
|
1178
|
+
const { name, intro, marks, attributes } = this.apiToSwaggerOrigin.project || {};
|
|
808
1179
|
this.apiToSwaggerResult.info = {
|
|
809
1180
|
title: name || "New Project",
|
|
810
1181
|
description: intro || "",
|
|
@@ -816,51 +1187,44 @@ class ApipostToSwagger {
|
|
|
816
1187
|
else if (this.apiToSwaggerVersion == "3.0") {
|
|
817
1188
|
this.apiToSwaggerResult.openapi = "3.0.0";
|
|
818
1189
|
}
|
|
1190
|
+
if (lodash.isArray(marks) && marks.length > 0) {
|
|
1191
|
+
this.apiToSwaggerResult.info['x-marks'] = marks;
|
|
1192
|
+
}
|
|
1193
|
+
if (lodash.isArray(attributes) && attributes.length > 0) {
|
|
1194
|
+
this.apiToSwaggerResult.info['x-attributes'] = attributes;
|
|
1195
|
+
}
|
|
819
1196
|
}
|
|
820
1197
|
handleModels() {
|
|
821
|
-
var _a;
|
|
1198
|
+
var _a, _b;
|
|
822
1199
|
const version = this.apiToSwaggerVersion;
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
item["modelPath"] = modelPath;
|
|
840
|
-
}
|
|
841
|
-
modelsPathObj[modelPath] = item;
|
|
842
|
-
lastObj[item.model_id] = item;
|
|
843
|
-
return lastObj;
|
|
844
|
-
}
|
|
845
|
-
}, {});
|
|
846
|
-
components.schemas = Object.keys(modelsPathObj).reduce((lastObj, key) => {
|
|
847
|
-
const modelObj = modelsPathObj[key];
|
|
848
|
-
if (!lodash.has(modelObj, "schema") || !lodash.isPlainObject(modelObj.schema)) {
|
|
849
|
-
modelObj.schema = {};
|
|
1200
|
+
const childModels = (_a = this.apiToSwaggerOrigin.models) === null || _a === void 0 ? void 0 : _a.filter((item) => (item === null || item === void 0 ? void 0 : item.model_type) === "model");
|
|
1201
|
+
// 声明一个schema映射表
|
|
1202
|
+
const schemaMap = childModels === null || childModels === void 0 ? void 0 : childModels.reduce((pre, item) => {
|
|
1203
|
+
if ((item === null || item === void 0 ? void 0 : item.model_id) && (item === null || item === void 0 ? void 0 : item.name)) {
|
|
1204
|
+
pre[item === null || item === void 0 ? void 0 : item.model_id] = {
|
|
1205
|
+
schema: (item === null || item === void 0 ? void 0 : item.schema) || { type: 'object', properties: {} },
|
|
1206
|
+
path: schemaPath(item === null || item === void 0 ? void 0 : item.name, version),
|
|
1207
|
+
name: (item === null || item === void 0 ? void 0 : item.name) || '',
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
return pre;
|
|
1211
|
+
}, {});
|
|
1212
|
+
if (lodash.isArray(childModels) && childModels.length > 0) {
|
|
1213
|
+
const schemas = (_b = lodash.values(schemaMap)) === null || _b === void 0 ? void 0 : _b.reduce((pre, item) => {
|
|
1214
|
+
if ((item === null || item === void 0 ? void 0 : item.name) && (item === null || item === void 0 ? void 0 : item.schema)) {
|
|
1215
|
+
pre[item === null || item === void 0 ? void 0 : item.name] = deepModelRef(item === null || item === void 0 ? void 0 : item.schema, schemaMap);
|
|
850
1216
|
}
|
|
851
|
-
|
|
852
|
-
// 处理完所有当前模型所有引用
|
|
853
|
-
lastObj[key] = deepHandleModelRef(modelObj.schema, modelsObj, version);
|
|
854
|
-
return lastObj;
|
|
1217
|
+
return pre;
|
|
855
1218
|
}, {});
|
|
856
|
-
|
|
857
|
-
|
|
1219
|
+
// 先不区分目录概念 把所有的schema都放在schemas目录下 后期加上schemas生成多目录
|
|
1220
|
+
if (version === '2.0') {
|
|
1221
|
+
this.apiToSwaggerResult.definitions = schemas;
|
|
858
1222
|
}
|
|
859
|
-
|
|
860
|
-
this.apiToSwaggerResult.components =
|
|
1223
|
+
if (lodash.isEqual(version, '3.0') || lodash.isEqual(version, '3.0.0')) {
|
|
1224
|
+
this.apiToSwaggerResult.components = { schemas };
|
|
861
1225
|
}
|
|
862
1226
|
}
|
|
863
|
-
return
|
|
1227
|
+
return schemaMap;
|
|
864
1228
|
}
|
|
865
1229
|
handleEnvs() {
|
|
866
1230
|
const envs = this.apiToSwaggerOrigin.envs;
|
|
@@ -937,7 +1301,7 @@ class ApipostToSwagger {
|
|
|
937
1301
|
this.apiToSwaggerResult.paths = tempPaths;
|
|
938
1302
|
}
|
|
939
1303
|
array2NamePathObj(idName = "id", pidName = "pid", modelsObj) {
|
|
940
|
-
var _a, _b, _c, _d, _e
|
|
1304
|
+
var _a, _b, _c, _d, _e;
|
|
941
1305
|
const items = this.apiToSwaggerOrigin.apis;
|
|
942
1306
|
try {
|
|
943
1307
|
const paths = {};
|
|
@@ -952,57 +1316,82 @@ class ApipostToSwagger {
|
|
|
952
1316
|
if (!id || id == undefined) {
|
|
953
1317
|
continue;
|
|
954
1318
|
}
|
|
955
|
-
if (item.target_type
|
|
1319
|
+
if (['sse', 'api'].includes(item.target_type)) {
|
|
956
1320
|
const temp_url = removeQuery(item === null || item === void 0 ? void 0 : item.url);
|
|
957
|
-
const
|
|
958
|
-
const
|
|
959
|
-
|
|
960
|
-
if (!lodash.has(paths, temp_url)) {
|
|
1321
|
+
const targetMethod = (_a = item === null || item === void 0 ? void 0 : item.method) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
1322
|
+
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type == 'api' ? 'http' : item.target_type);
|
|
1323
|
+
if (!paths[temp_url])
|
|
961
1324
|
paths[temp_url] = {};
|
|
962
|
-
|
|
963
|
-
if (!lodash.has(paths[temp_url], targetMethod)) {
|
|
964
|
-
const pathItem = {
|
|
965
|
-
summary: (item === null || item === void 0 ? void 0 : item.name) || "",
|
|
966
|
-
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
967
|
-
tags: (item === null || item === void 0 ? void 0 : item.tags) || [],
|
|
968
|
-
};
|
|
969
|
-
handlePathItemParameters("query", ((_c = (_b = item === null || item === void 0 ? void 0 : item.request) === null || _b === void 0 ? void 0 : _b.query) === null || _c === void 0 ? void 0 : _c.parameter) || [], pathItem);
|
|
970
|
-
handlePathItemParameters("header", ((_e = (_d = item === null || item === void 0 ? void 0 : item.request) === null || _d === void 0 ? void 0 : _d.header) === null || _e === void 0 ? void 0 : _e.parameter) || [], pathItem);
|
|
971
|
-
if (this.apiToSwaggerVersion == "2.0") {
|
|
972
|
-
handlePathItemBodyParameters(((_f = item === null || item === void 0 ? void 0 : item.request) === null || _f === void 0 ? void 0 : _f.body) || {}, pathItem, modelsObj);
|
|
973
|
-
}
|
|
974
|
-
else {
|
|
975
|
-
handlePathItemrequestBody(((_g = item === null || item === void 0 ? void 0 : item.request) === null || _g === void 0 ? void 0 : _g.body) || {}, pathItem);
|
|
976
|
-
}
|
|
977
|
-
pathItem.requestBody = deepHandleModelRef(pathItem.requestBody, modelsObj, this.apiToSwaggerVersion);
|
|
978
|
-
if (path && path.length > 0 && !pathItem.tags.includes(path)) {
|
|
979
|
-
pathItem.tags = [...pathItem.tags, path];
|
|
980
|
-
}
|
|
981
|
-
// 添加响应期望 responses
|
|
982
|
-
pathItem.responses = handelPathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {});
|
|
983
|
-
pathItem.responses = deepHandleModelRef(pathItem.responses, modelsObj, this.apiToSwaggerVersion);
|
|
1325
|
+
if (!paths[temp_url][targetMethod]) {
|
|
984
1326
|
paths[temp_url][targetMethod] = pathItem;
|
|
985
1327
|
}
|
|
986
|
-
else if (
|
|
987
|
-
|
|
988
|
-
!((_h = paths[temp_url][targetMethod]) === null || _h === void 0 ? void 0 : _h.tags.includes(path))) {
|
|
989
|
-
(_j = paths[temp_url][targetMethod]) === null || _j === void 0 ? void 0 : _j.tags.push(path);
|
|
1328
|
+
else if (pathItem.tags.length > 0) {
|
|
1329
|
+
paths[temp_url][targetMethod].tags.push(...pathItem.tags);
|
|
990
1330
|
}
|
|
991
1331
|
}
|
|
992
|
-
else if (item.target_type
|
|
1332
|
+
else if (["folder", "socket"].includes(item.target_type)) {
|
|
993
1333
|
const path = recursiveFolderPath(`${item === null || item === void 0 ? void 0 : item.name}`, sourceObj, pid, pidName);
|
|
994
1334
|
item.path = path;
|
|
995
1335
|
if (!lodash.has(folderObj, item === null || item === void 0 ? void 0 : item.name)) {
|
|
996
1336
|
if (!this.apiToSwaggerResult.tags) {
|
|
997
1337
|
this.apiToSwaggerResult.tags = [];
|
|
998
1338
|
}
|
|
1339
|
+
// 收到数据即认为完成(不处理分包问题) none
|
|
1340
|
+
if (item.target_type === 'socket' && lodash.isPlainObject((_b = item === null || item === void 0 ? void 0 : item.request) === null || _b === void 0 ? void 0 : _b.end_func)) {
|
|
1341
|
+
item.description = `| Server address | Determine the completion mode of receiving packets |
|
|
1342
|
+
| --- | --- |
|
|
1343
|
+
| ${item === null || item === void 0 ? void 0 : item.url} | ${getSocketRequestStr((_c = item === null || item === void 0 ? void 0 : item.request) === null || _c === void 0 ? void 0 : _c.end_func)}
|
|
1344
|
+
${item.description}
|
|
1345
|
+
`;
|
|
1346
|
+
}
|
|
999
1347
|
this.apiToSwaggerResult.tags.push({
|
|
1000
1348
|
name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
|
|
1001
1349
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
1350
|
+
'x-type': item.target_type,
|
|
1351
|
+
'x-url': (item === null || item === void 0 ? void 0 : item.url) || ''
|
|
1002
1352
|
});
|
|
1003
1353
|
folderObj[item === null || item === void 0 ? void 0 : item.name] = item;
|
|
1004
1354
|
}
|
|
1005
1355
|
}
|
|
1356
|
+
else if (['websocket2', 'socketio', 'graphql'].includes(item.target_type)) {
|
|
1357
|
+
const temp_url = removeQuery(item === null || item === void 0 ? void 0 : item.url);
|
|
1358
|
+
const targetMethod = `x-${item === null || item === void 0 ? void 0 : item.target_id}`;
|
|
1359
|
+
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
|
|
1360
|
+
if (!paths[temp_url])
|
|
1361
|
+
paths[temp_url] = {};
|
|
1362
|
+
if (!paths[temp_url][targetMethod]) {
|
|
1363
|
+
paths[temp_url][targetMethod] = pathItem;
|
|
1364
|
+
}
|
|
1365
|
+
else if (pathItem.tags.length > 0) {
|
|
1366
|
+
paths[temp_url][targetMethod].tags.push(...pathItem.tags);
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
else if (item.target_type === 'socket_method') {
|
|
1370
|
+
const temp_url = (sourceObj === null || sourceObj === void 0 ? void 0 : sourceObj[pid]) && ((_d = sourceObj[pid]) === null || _d === void 0 ? void 0 : _d.url) ? (_e = sourceObj[pid]) === null || _e === void 0 ? void 0 : _e.url : `${item === null || item === void 0 ? void 0 : item.name}`;
|
|
1371
|
+
const targetMethod = `x-${item.target_id}`;
|
|
1372
|
+
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
|
|
1373
|
+
if (!paths[temp_url])
|
|
1374
|
+
paths[temp_url] = {};
|
|
1375
|
+
if (!paths[temp_url][targetMethod]) {
|
|
1376
|
+
paths[temp_url][targetMethod] = pathItem;
|
|
1377
|
+
}
|
|
1378
|
+
else if (pathItem.tags.length > 0) {
|
|
1379
|
+
paths[temp_url][targetMethod].tags.push(...pathItem.tags);
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
else if (item.target_type === 'doc') {
|
|
1383
|
+
const temp_url = `x-${item.target_id}`;
|
|
1384
|
+
const targetMethod = `x-${item === null || item === void 0 ? void 0 : item.name}`;
|
|
1385
|
+
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
|
|
1386
|
+
if (!paths[temp_url])
|
|
1387
|
+
paths[temp_url] = {};
|
|
1388
|
+
if (!paths[temp_url][targetMethod]) {
|
|
1389
|
+
paths[temp_url][targetMethod] = pathItem;
|
|
1390
|
+
}
|
|
1391
|
+
else if (pathItem.tags.length > 0) {
|
|
1392
|
+
paths[temp_url][targetMethod].tags.push(...pathItem.tags);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1006
1395
|
}
|
|
1007
1396
|
return {
|
|
1008
1397
|
paths,
|
|
@@ -1041,9 +1430,9 @@ class ApipostToSwagger {
|
|
|
1041
1430
|
// 处理项目信息
|
|
1042
1431
|
this.handleProject();
|
|
1043
1432
|
// 处理数据模型
|
|
1044
|
-
const
|
|
1433
|
+
const schemaMap = this.handleModels();
|
|
1045
1434
|
// // 处理apis
|
|
1046
|
-
this.handleApis(
|
|
1435
|
+
this.handleApis(schemaMap);
|
|
1047
1436
|
// 处理环境信息
|
|
1048
1437
|
this.handleEnvs();
|
|
1049
1438
|
if (`${version}` === "metersphere") {
|
|
@@ -1052,6 +1441,7 @@ class ApipostToSwagger {
|
|
|
1052
1441
|
return throwResult$1("success", "", this.apiToSwaggerResult);
|
|
1053
1442
|
}
|
|
1054
1443
|
catch (error) {
|
|
1444
|
+
console.log(JSON.stringify(error.message), "error");
|
|
1055
1445
|
return throwResult$1("error", String(error), this.apiToSwaggerResult);
|
|
1056
1446
|
}
|
|
1057
1447
|
}
|
|
@@ -1574,8 +1964,8 @@ class SwaggerToApipost {
|
|
|
1574
1964
|
}
|
|
1575
1965
|
}
|
|
1576
1966
|
handlePathV3(path, pathItem, tags) {
|
|
1577
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1578
1967
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1968
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1579
1969
|
let url = path;
|
|
1580
1970
|
for (const method in pathItem) {
|
|
1581
1971
|
const swaggerApi = pathItem[method];
|
|
@@ -1992,8 +2382,8 @@ class SwaggerToApipost {
|
|
|
1992
2382
|
});
|
|
1993
2383
|
}
|
|
1994
2384
|
handlePathsV3(json) {
|
|
1995
|
-
var _a, _b;
|
|
1996
2385
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2386
|
+
var _a, _b;
|
|
1997
2387
|
try {
|
|
1998
2388
|
const paths = ((_a = json === null || json === void 0 ? void 0 : json.openapi) === null || _a === void 0 ? void 0 : _a.paths) || json.paths;
|
|
1999
2389
|
const tags = ((_b = json === null || json === void 0 ? void 0 : json.openapi) === null || _b === void 0 ? void 0 : _b.tags) || json.tags;
|
|
@@ -2025,8 +2415,8 @@ class SwaggerToApipost {
|
|
|
2025
2415
|
}
|
|
2026
2416
|
}
|
|
2027
2417
|
handlePath(path, pathItem, tags) {
|
|
2028
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2029
2418
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2419
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2030
2420
|
let url = path;
|
|
2031
2421
|
url = decodeURI(this.basePath + url);
|
|
2032
2422
|
url = fixUrlPath(url);
|
|
@@ -2433,8 +2823,8 @@ class SwaggerToApipost {
|
|
|
2433
2823
|
catch (err) { }
|
|
2434
2824
|
});
|
|
2435
2825
|
}
|
|
2436
|
-
convert(
|
|
2437
|
-
return __awaiter(this,
|
|
2826
|
+
convert(json_1) {
|
|
2827
|
+
return __awaiter(this, arguments, void 0, function* (json, options = null) {
|
|
2438
2828
|
this.clear();
|
|
2439
2829
|
try {
|
|
2440
2830
|
if (options && options instanceof Object) {
|