echoapi-converter 0.0.75 → 0.0.77
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 +2222 -2205
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var lodash = require('lodash');
|
|
6
|
-
var i18next = require('i18next');
|
|
7
|
-
var apipostTools = require('apipost-tools');
|
|
8
6
|
var urlParse = require('url-parse');
|
|
7
|
+
var apipostTools = require('apipost-tools');
|
|
8
|
+
var i18next = require('i18next');
|
|
9
9
|
var MockSchema = require('apipost-mock-schema');
|
|
10
10
|
var axios = require('axios');
|
|
11
11
|
var SwaggerClient = require('swagger-client');
|
|
@@ -14,8 +14,8 @@ var JSON5 = require('json5');
|
|
|
14
14
|
|
|
15
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
16
|
|
|
17
|
-
var i18next__default = /*#__PURE__*/_interopDefaultLegacy(i18next);
|
|
18
17
|
var urlParse__default = /*#__PURE__*/_interopDefaultLegacy(urlParse);
|
|
18
|
+
var i18next__default = /*#__PURE__*/_interopDefaultLegacy(i18next);
|
|
19
19
|
var MockSchema__default = /*#__PURE__*/_interopDefaultLegacy(MockSchema);
|
|
20
20
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
21
21
|
var SwaggerClient__default = /*#__PURE__*/_interopDefaultLegacy(SwaggerClient);
|
|
@@ -344,993 +344,618 @@ const RULE_TYPES = {
|
|
|
344
344
|
12: '(\\r\\n)',
|
|
345
345
|
};
|
|
346
346
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
var left$4 = "Left";
|
|
354
|
-
var right$4 = "Right";
|
|
355
|
-
var tcpMethodMessage$4 = "{{direction}} pad to a length of {{size}}, padding character: {{str}}";
|
|
356
|
-
var tcpMethodDelimiterMessage$4 = "Append the separator character {{str}} at the end.";
|
|
357
|
-
var requestEncodingFormat$4 = "The encoding format for the request message is {{format}}.";
|
|
358
|
-
var needAddRequestDataHandleFunction$4 = "Request data processing function needs to be added:";
|
|
359
|
-
var needAddResponseDataHandleFunction$4 = "Response data processing function needs to be added:";
|
|
360
|
-
var addNewline$4 = "Add a newline character {{str}} at the end of each request message";
|
|
361
|
-
var addContentLength$4 = "calculate the content length (excluding the packet header), and append it to the packet header (text format, packet header byte length is {{size}}).";
|
|
362
|
-
var removeResponseHeader$4 = "The response message needs to remove the packet header (length of {{size}} bytes)";
|
|
363
|
-
var trimTrailingNewline$4 = "strip the newline character {{str}} at the end of the line";
|
|
364
|
-
var convertXmlToJson$4 = "and convert the XML content to JSON format.";
|
|
365
|
-
var specialCharText$4 = "For text-type messages, the packet tail contains special character {{str}}";
|
|
366
|
-
var specialCharBinary$4 = "For binary-type messages, the packet tail contains special character {{str}}";
|
|
367
|
-
var headerBodyFormat$4 = "[Header+Body] formatted message (header contains the byte length of the body), with a header length of {{size}} bytes";
|
|
368
|
-
var fixedLength$4 = "The message has a fixed length of {{size}} bytes";
|
|
369
|
-
var byte$4 = "bytes";
|
|
370
|
-
var completeOnReceive$4 = "Completion is assumed upon data reception (subpacket handling is not addressed)";
|
|
371
|
-
var serverAddress$4 = "Server address";
|
|
372
|
-
var pktCompletion$4 = "Method to determine message reception completio";
|
|
373
|
-
var createDir$4 = "Create directory";
|
|
374
|
-
var createProj$4 = "Create project";
|
|
375
|
-
var createEnv$4 = "Create environment";
|
|
376
|
-
var en = {
|
|
377
|
-
securityConnectionMessageNoPath: securityConnectionMessageNoPath$4,
|
|
378
|
-
notNeedEnable: notNeedEnable$4,
|
|
379
|
-
needEnable: needEnable$4,
|
|
380
|
-
securityConnectionMessage: securityConnectionMessage$4,
|
|
381
|
-
wsConfigMessage: wsConfigMessage$4,
|
|
382
|
-
unlimited: unlimited$4,
|
|
383
|
-
left: left$4,
|
|
384
|
-
right: right$4,
|
|
385
|
-
tcpMethodMessage: tcpMethodMessage$4,
|
|
386
|
-
tcpMethodDelimiterMessage: tcpMethodDelimiterMessage$4,
|
|
387
|
-
requestEncodingFormat: requestEncodingFormat$4,
|
|
388
|
-
needAddRequestDataHandleFunction: needAddRequestDataHandleFunction$4,
|
|
389
|
-
needAddResponseDataHandleFunction: needAddResponseDataHandleFunction$4,
|
|
390
|
-
addNewline: addNewline$4,
|
|
391
|
-
addContentLength: addContentLength$4,
|
|
392
|
-
removeResponseHeader: removeResponseHeader$4,
|
|
393
|
-
trimTrailingNewline: trimTrailingNewline$4,
|
|
394
|
-
convertXmlToJson: convertXmlToJson$4,
|
|
395
|
-
specialCharText: specialCharText$4,
|
|
396
|
-
specialCharBinary: specialCharBinary$4,
|
|
397
|
-
headerBodyFormat: headerBodyFormat$4,
|
|
398
|
-
fixedLength: fixedLength$4,
|
|
399
|
-
byte: byte$4,
|
|
400
|
-
completeOnReceive: completeOnReceive$4,
|
|
401
|
-
serverAddress: serverAddress$4,
|
|
402
|
-
pktCompletion: pktCompletion$4,
|
|
403
|
-
createDir: createDir$4,
|
|
404
|
-
createProj: createProj$4,
|
|
405
|
-
createEnv: createEnv$4
|
|
347
|
+
const throwResult$1 = (status, message, data = '') => {
|
|
348
|
+
return {
|
|
349
|
+
status,
|
|
350
|
+
message,
|
|
351
|
+
data,
|
|
352
|
+
};
|
|
406
353
|
};
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
var unlimited$3 = "tidak terbatas";
|
|
414
|
-
var left$3 = "Isi sisi kiri hingga";
|
|
415
|
-
var right$3 = "Isi sisi kanan hingga";
|
|
416
|
-
var tcpMethodMessage$3 = "{{direction}} {{size}} karakter, gunakan karakter pengisi '{{str}}'.";
|
|
417
|
-
var tcpMethodDelimiterMessage$3 = "Tambahkan karakter pemisah {{str}} di akhir.";
|
|
418
|
-
var requestEncodingFormat$3 = "Format pengkodean untuk pesan permintaan adalah {{format}}.";
|
|
419
|
-
var needAddRequestDataHandleFunction$3 = "Perlu menambahkan fungsi pemrosesan data permintaan:";
|
|
420
|
-
var needAddResponseDataHandleFunction$3 = "Perlu menambahkan fungsi pemrosesan data respons:";
|
|
421
|
-
var addNewline$3 = "Tambahkan karakter baris baru {{str}} di akhir setiap pesan permintaan";
|
|
422
|
-
var addContentLength$3 = "hitung panjang konten (tidak termasuk header paket), dan tambahkan ke header paket (format teks, panjang byte header paket adalah {{size}}).";
|
|
423
|
-
var removeResponseHeader$3 = "Pesan respons perlu menghapus header paket (panjang {{size}} byte)";
|
|
424
|
-
var trimTrailingNewline$3 = "menghapus karakter baris baru {{str}} di akhir baris";
|
|
425
|
-
var convertXmlToJson$3 = "dan mengonversi konten dalam format XML menjadi format JSON.";
|
|
426
|
-
var specialCharText$3 = "Untuk pesan tipe teks, ujung paket mengandung karakter khusus {{str}}";
|
|
427
|
-
var specialCharBinary$3 = "Untuk pesan tipe biner, ujung paket mengandung karakter khusus {{str}}";
|
|
428
|
-
var headerBodyFormat$3 = "Pesan berformat [Kepala+Isi] (Kepala menyimpan panjang byte Isi), dengan panjang Kepala {{size}} byte";
|
|
429
|
-
var fixedLength$3 = "Pesan memiliki panjang tetap ({{size}} byte)";
|
|
430
|
-
var byte$3 = "byte";
|
|
431
|
-
var completeOnReceive$3 = "Anggap data diterima sebagai lengkap (tanpa menangani segmentasi paket)";
|
|
432
|
-
var serverAddress$3 = "Alamat server";
|
|
433
|
-
var pktCompletion$3 = "Tentukan metode penyelesaian penerimaan pesan";
|
|
434
|
-
var createDir$3 = "Buat direktori";
|
|
435
|
-
var createProj$3 = "Buat proyek";
|
|
436
|
-
var createEnv$3 = "Buat lingkungan";
|
|
437
|
-
var id = {
|
|
438
|
-
securityConnectionMessageNoPath: securityConnectionMessageNoPath$3,
|
|
439
|
-
notNeedEnable: notNeedEnable$3,
|
|
440
|
-
needEnable: needEnable$3,
|
|
441
|
-
securityConnectionMessage: securityConnectionMessage$3,
|
|
442
|
-
wsConfigMessage: wsConfigMessage$3,
|
|
443
|
-
unlimited: unlimited$3,
|
|
444
|
-
left: left$3,
|
|
445
|
-
right: right$3,
|
|
446
|
-
tcpMethodMessage: tcpMethodMessage$3,
|
|
447
|
-
tcpMethodDelimiterMessage: tcpMethodDelimiterMessage$3,
|
|
448
|
-
requestEncodingFormat: requestEncodingFormat$3,
|
|
449
|
-
needAddRequestDataHandleFunction: needAddRequestDataHandleFunction$3,
|
|
450
|
-
needAddResponseDataHandleFunction: needAddResponseDataHandleFunction$3,
|
|
451
|
-
addNewline: addNewline$3,
|
|
452
|
-
addContentLength: addContentLength$3,
|
|
453
|
-
removeResponseHeader: removeResponseHeader$3,
|
|
454
|
-
trimTrailingNewline: trimTrailingNewline$3,
|
|
455
|
-
convertXmlToJson: convertXmlToJson$3,
|
|
456
|
-
specialCharText: specialCharText$3,
|
|
457
|
-
specialCharBinary: specialCharBinary$3,
|
|
458
|
-
headerBodyFormat: headerBodyFormat$3,
|
|
459
|
-
fixedLength: fixedLength$3,
|
|
460
|
-
byte: byte$3,
|
|
461
|
-
completeOnReceive: completeOnReceive$3,
|
|
462
|
-
serverAddress: serverAddress$3,
|
|
463
|
-
pktCompletion: pktCompletion$3,
|
|
464
|
-
createDir: createDir$3,
|
|
465
|
-
createProj: createProj$3,
|
|
466
|
-
createEnv: createEnv$3
|
|
354
|
+
const transExample = (example) => {
|
|
355
|
+
if (lodash.isString(example))
|
|
356
|
+
return example;
|
|
357
|
+
if (lodash.isNumber(example))
|
|
358
|
+
return String(example);
|
|
359
|
+
return example;
|
|
467
360
|
};
|
|
468
|
-
|
|
469
|
-
var
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
var requestEncodingFormat$2 = "リクエストメッセージのエンコーディング形式は{{format}}です。";
|
|
480
|
-
var needAddRequestDataHandleFunction$2 = "リクエストデータ処理関数を追加する必要があります:";
|
|
481
|
-
var needAddResponseDataHandleFunction$2 = "応答データ処理関数を追加する必要があります:";
|
|
482
|
-
var addNewline$2 = "各リクエストメッセージの末尾に改行文字{{str}}を追加し";
|
|
483
|
-
var addContentLength$2 = "内容の長さを計算(パケットヘッダーを除く)して、それをパケットヘッダーに追加します(テキスト形式、パケットヘッダーのバイト長は{{size}}です)。";
|
|
484
|
-
var removeResponseHeader$2 = "応答メッセージは、パケットヘッダー(長さ{{size}}バイト)";
|
|
485
|
-
var trimTrailingNewline$2 = "を削除し、行末の改行文字{{str}}を取り除き";
|
|
486
|
-
var convertXmlToJson$2 = "XML形式の内容をJSON形式に変換する必要があります。";
|
|
487
|
-
var specialCharText$2 = "テキストタイプのメッセージでは、パケットの末尾に特殊文字 {{str}} が含まれています";
|
|
488
|
-
var specialCharBinary$2 = "バイナリタイプのメッセージでは、パケットの末尾に特殊文字 {{str}} が含まれています";
|
|
489
|
-
var headerBodyFormat$2 = "[ヘッダー+ボディ]フォーマットのメッセージ(ヘッダーにはボディのバイト長が含まれ、ヘッダー長は{{size}}バイトです)";
|
|
490
|
-
var fixedLength$2 = "メッセージは固定長({{size}}バイト)です";
|
|
491
|
-
var byte$2 = "バイト";
|
|
492
|
-
var completeOnReceive$2 = "データを受信した時点で完了とみなします(パケット分割は処理しません)";
|
|
493
|
-
var serverAddress$2 = "サーバーアドレス";
|
|
494
|
-
var pktCompletion$2 = "メッセージ受信完了方法を判断する";
|
|
495
|
-
var createDir$2 = "ディレクトリを作成する";
|
|
496
|
-
var createProj$2 = "プロジェクトを作成する";
|
|
497
|
-
var createEnv$2 = "環境を作成する";
|
|
498
|
-
var ja = {
|
|
499
|
-
securityConnectionMessageNoPath: securityConnectionMessageNoPath$2,
|
|
500
|
-
notNeedEnable: notNeedEnable$2,
|
|
501
|
-
needEnable: needEnable$2,
|
|
502
|
-
securityConnectionMessage: securityConnectionMessage$2,
|
|
503
|
-
wsConfigMessage: wsConfigMessage$2,
|
|
504
|
-
unlimited: unlimited$2,
|
|
505
|
-
left: left$2,
|
|
506
|
-
right: right$2,
|
|
507
|
-
tcpMethodMessage: tcpMethodMessage$2,
|
|
508
|
-
tcpMethodDelimiterMessage: tcpMethodDelimiterMessage$2,
|
|
509
|
-
requestEncodingFormat: requestEncodingFormat$2,
|
|
510
|
-
needAddRequestDataHandleFunction: needAddRequestDataHandleFunction$2,
|
|
511
|
-
needAddResponseDataHandleFunction: needAddResponseDataHandleFunction$2,
|
|
512
|
-
addNewline: addNewline$2,
|
|
513
|
-
addContentLength: addContentLength$2,
|
|
514
|
-
removeResponseHeader: removeResponseHeader$2,
|
|
515
|
-
trimTrailingNewline: trimTrailingNewline$2,
|
|
516
|
-
convertXmlToJson: convertXmlToJson$2,
|
|
517
|
-
specialCharText: specialCharText$2,
|
|
518
|
-
specialCharBinary: specialCharBinary$2,
|
|
519
|
-
headerBodyFormat: headerBodyFormat$2,
|
|
520
|
-
fixedLength: fixedLength$2,
|
|
521
|
-
byte: byte$2,
|
|
522
|
-
completeOnReceive: completeOnReceive$2,
|
|
523
|
-
serverAddress: serverAddress$2,
|
|
524
|
-
pktCompletion: pktCompletion$2,
|
|
525
|
-
createDir: createDir$2,
|
|
526
|
-
createProj: createProj$2,
|
|
527
|
-
createEnv: createEnv$2
|
|
361
|
+
const getBeautifulRaw$1 = (raw) => {
|
|
362
|
+
var _a;
|
|
363
|
+
try {
|
|
364
|
+
if (!raw) {
|
|
365
|
+
return raw;
|
|
366
|
+
}
|
|
367
|
+
return (_a = apipostTools.beautifyRaw(raw)) === null || _a === void 0 ? void 0 : _a.value;
|
|
368
|
+
}
|
|
369
|
+
catch (err) {
|
|
370
|
+
return raw;
|
|
371
|
+
}
|
|
528
372
|
};
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
var notNeedEnable$1 = "无需启用";
|
|
532
|
-
var needEnable$1 = "请启用";
|
|
533
|
-
var securityConnectionMessage$1 = "在通过安全连接时,{{enable}}服务器证书验证,并使用客户端版本 {{version}} ,指定握手路径为 {{path}} 。";
|
|
534
|
-
var wsConfigMessage$1 = "在通过安全连接时,{{enable}}服务器证书验证,并且允许接收的最大發送内容为{{content}}。";
|
|
535
|
-
var unlimited$1 = "无限制";
|
|
536
|
-
var left$1 = "左";
|
|
537
|
-
var right$1 = "右";
|
|
538
|
-
var tcpMethodMessage$1 = "{{direction}}填充至长度{{size}},填充字符为:{{str}}";
|
|
539
|
-
var tcpMethodDelimiterMessage$1 = "结尾添加分隔字符{{str}}";
|
|
540
|
-
var requestEncodingFormat$1 = "请求报文的编码格式为 {{format}}";
|
|
541
|
-
var needAddRequestDataHandleFunction$1 = "需要添加请求数据处理函数:";
|
|
542
|
-
var needAddResponseDataHandleFunction$1 = "需要添加请求数据处理函数:";
|
|
543
|
-
var addNewline$1 = "在每个请求报文的结尾添加换行符 {{str}}";
|
|
544
|
-
var addContentLength$1 = "计算内容长度(不包括包头)并将其添加到包头(文本格式,包头字节长度为 {{size}})";
|
|
545
|
-
var removeResponseHeader$1 = "响应报文需要去除包头(长度为 {{size}} 字节)";
|
|
546
|
-
var trimTrailingNewline$1 = "去除行尾的换行符 {{str}}";
|
|
547
|
-
var convertXmlToJson$1 = "将 XML 格式的内容转换为 JSON 格式。";
|
|
548
|
-
var specialCharText$1 = "文本类型的报文,包尾含特殊字符 {{str}}";
|
|
549
|
-
var specialCharBinary$1 = "二进制类型的报文,包尾含特殊字符 {{str}}";
|
|
550
|
-
var headerBodyFormat$1 = "[包头+包体]格式报文(包头存包体字节长度),包头长度为{{size}}字节";
|
|
551
|
-
var fixedLength$1 = "报文为固定长度({{size}}字节)";
|
|
552
|
-
var byte$1 = "字节";
|
|
553
|
-
var completeOnReceive$1 = "收到数据即认为完成(不处理分包问题)";
|
|
554
|
-
var serverAddress$1 = "服务端地址";
|
|
555
|
-
var pktCompletion$1 = "判断报文接收完成方式";
|
|
556
|
-
var createDir$1 = "新建目录";
|
|
557
|
-
var createProj$1 = "新建项目";
|
|
558
|
-
var createEnv$1 = "新建环境";
|
|
559
|
-
var cn = {
|
|
560
|
-
securityConnectionMessageNoPath: securityConnectionMessageNoPath$1,
|
|
561
|
-
notNeedEnable: notNeedEnable$1,
|
|
562
|
-
needEnable: needEnable$1,
|
|
563
|
-
securityConnectionMessage: securityConnectionMessage$1,
|
|
564
|
-
wsConfigMessage: wsConfigMessage$1,
|
|
565
|
-
unlimited: unlimited$1,
|
|
566
|
-
left: left$1,
|
|
567
|
-
right: right$1,
|
|
568
|
-
tcpMethodMessage: tcpMethodMessage$1,
|
|
569
|
-
tcpMethodDelimiterMessage: tcpMethodDelimiterMessage$1,
|
|
570
|
-
requestEncodingFormat: requestEncodingFormat$1,
|
|
571
|
-
needAddRequestDataHandleFunction: needAddRequestDataHandleFunction$1,
|
|
572
|
-
needAddResponseDataHandleFunction: needAddResponseDataHandleFunction$1,
|
|
573
|
-
addNewline: addNewline$1,
|
|
574
|
-
addContentLength: addContentLength$1,
|
|
575
|
-
removeResponseHeader: removeResponseHeader$1,
|
|
576
|
-
trimTrailingNewline: trimTrailingNewline$1,
|
|
577
|
-
convertXmlToJson: convertXmlToJson$1,
|
|
578
|
-
specialCharText: specialCharText$1,
|
|
579
|
-
specialCharBinary: specialCharBinary$1,
|
|
580
|
-
headerBodyFormat: headerBodyFormat$1,
|
|
581
|
-
fixedLength: fixedLength$1,
|
|
582
|
-
byte: byte$1,
|
|
583
|
-
completeOnReceive: completeOnReceive$1,
|
|
584
|
-
serverAddress: serverAddress$1,
|
|
585
|
-
pktCompletion: pktCompletion$1,
|
|
586
|
-
createDir: createDir$1,
|
|
587
|
-
createProj: createProj$1,
|
|
588
|
-
createEnv: createEnv$1
|
|
373
|
+
const isArray = (value) => {
|
|
374
|
+
return Object.prototype.toString.call(value) === "[object Array]";
|
|
589
375
|
};
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
var notNeedEnable = "無需啟用";
|
|
593
|
-
var needEnable = "請啟用";
|
|
594
|
-
var securityConnectionMessage = "在通過安全連接時,{{enable}}伺服器證書驗證,並使用客戶端版本{{version}},指定握手路徑為{{path}}。";
|
|
595
|
-
var wsConfigMessage = "在通過安全連接時,{{enable}}伺服器證書驗證,並且允許接收的最大發送內容為 {{content}}。";
|
|
596
|
-
var unlimited = "無限制";
|
|
597
|
-
var left = "左";
|
|
598
|
-
var right = "右";
|
|
599
|
-
var tcpMethodMessage = "{{direction}}填充至長度{{size}},填充字符為:{{str}}";
|
|
600
|
-
var tcpMethodDelimiterMessage = "結尾添加分隔字符{{str}}";
|
|
601
|
-
var requestEncodingFormat = "請求報文的編碼格式為 {{format}}";
|
|
602
|
-
var needAddRequestDataHandleFunction = "需要添加請求數據處理函數:";
|
|
603
|
-
var needAddResponseDataHandleFunction = "需添加響應數據處理函數:";
|
|
604
|
-
var addNewline = "在每個請求報文的結尾添加換行符 {{str}}";
|
|
605
|
-
var addContentLength = "計算內容長度(不包括包頭)並將其添加到包頭(文本格式,包頭字節長度為 {{size}})";
|
|
606
|
-
var removeResponseHeader = "響應報文需要去除包頭(長度為 {{size}} 字節)";
|
|
607
|
-
var trimTrailingNewline = "去除行尾的換行符 {{str}}";
|
|
608
|
-
var convertXmlToJson = "將 XML 格式的內容轉換為 JSON 格式。";
|
|
609
|
-
var specialCharText = "文本類型的報文,包尾含特殊字符 {{str}}";
|
|
610
|
-
var specialCharBinary = "二進制類型的報文,包尾含特殊字符 {{str}}";
|
|
611
|
-
var headerBodyFormat = "[包頭+包體]格式報文(包頭存包體字節長度),包頭長度為{{size}}字節";
|
|
612
|
-
var fixedLength = "報文為固定長度({{size}}字節)";
|
|
613
|
-
var byte = "位元組";
|
|
614
|
-
var completeOnReceive = "收到數據即認為完成(不處理分包問題)";
|
|
615
|
-
var serverAddress = "伺服器地址";
|
|
616
|
-
var pktCompletion = "判斷報文接收完成方式";
|
|
617
|
-
var createDir = "新建目錄";
|
|
618
|
-
var createProj = "新建項目";
|
|
619
|
-
var createEnv = "新建環境";
|
|
620
|
-
var tw = {
|
|
621
|
-
securityConnectionMessageNoPath: securityConnectionMessageNoPath,
|
|
622
|
-
notNeedEnable: notNeedEnable,
|
|
623
|
-
needEnable: needEnable,
|
|
624
|
-
securityConnectionMessage: securityConnectionMessage,
|
|
625
|
-
wsConfigMessage: wsConfigMessage,
|
|
626
|
-
unlimited: unlimited,
|
|
627
|
-
left: left,
|
|
628
|
-
right: right,
|
|
629
|
-
tcpMethodMessage: tcpMethodMessage,
|
|
630
|
-
tcpMethodDelimiterMessage: tcpMethodDelimiterMessage,
|
|
631
|
-
requestEncodingFormat: requestEncodingFormat,
|
|
632
|
-
needAddRequestDataHandleFunction: needAddRequestDataHandleFunction,
|
|
633
|
-
needAddResponseDataHandleFunction: needAddResponseDataHandleFunction,
|
|
634
|
-
addNewline: addNewline,
|
|
635
|
-
addContentLength: addContentLength,
|
|
636
|
-
removeResponseHeader: removeResponseHeader,
|
|
637
|
-
trimTrailingNewline: trimTrailingNewline,
|
|
638
|
-
convertXmlToJson: convertXmlToJson,
|
|
639
|
-
specialCharText: specialCharText,
|
|
640
|
-
specialCharBinary: specialCharBinary,
|
|
641
|
-
headerBodyFormat: headerBodyFormat,
|
|
642
|
-
fixedLength: fixedLength,
|
|
643
|
-
byte: byte,
|
|
644
|
-
completeOnReceive: completeOnReceive,
|
|
645
|
-
serverAddress: serverAddress,
|
|
646
|
-
pktCompletion: pktCompletion,
|
|
647
|
-
createDir: createDir,
|
|
648
|
-
createProj: createProj,
|
|
649
|
-
createEnv: createEnv
|
|
376
|
+
const isObject = (value) => {
|
|
377
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
650
378
|
};
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
translation: en,
|
|
659
|
-
},
|
|
660
|
-
ja: {
|
|
661
|
-
translation: ja,
|
|
662
|
-
},
|
|
663
|
-
tw: {
|
|
664
|
-
translation: tw,
|
|
665
|
-
},
|
|
666
|
-
id: {
|
|
667
|
-
translation: id,
|
|
668
|
-
},
|
|
379
|
+
const isURL = (_url) => {
|
|
380
|
+
if (!_url) {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
_url = lodash.trim(_url);
|
|
384
|
+
return (_url.substr(0, 7).toLowerCase() === "http://" ||
|
|
385
|
+
_url.substr(0, 8).toLowerCase() === "https://");
|
|
669
386
|
};
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
*/
|
|
674
|
-
const I18nInit = (lng) => __awaiter(void 0, void 0, void 0, function* () {
|
|
675
|
-
// language= lng;
|
|
676
|
-
if (lng === 'zh-hant') {
|
|
677
|
-
lng = 'tw';
|
|
387
|
+
const createUrl = (_url) => {
|
|
388
|
+
if (typeof _url !== "string") {
|
|
389
|
+
_url += "";
|
|
678
390
|
}
|
|
679
|
-
if (!
|
|
680
|
-
|
|
681
|
-
yield i18nInstance.init({
|
|
682
|
-
lng: lng,
|
|
683
|
-
fallbackLng: 'zh-cn',
|
|
684
|
-
resources,
|
|
685
|
-
});
|
|
391
|
+
if (!isURL(_url)) {
|
|
392
|
+
_url = `http://${_url}`;
|
|
686
393
|
}
|
|
687
|
-
|
|
688
|
-
|
|
394
|
+
// eslint-disable-next-line no-useless-escape
|
|
395
|
+
const hostReg = /(http([s]?):\/\/)([^\/\?\\#]*)([\/|\?|\\#]?)/i;
|
|
396
|
+
const host_arr = _url.match(hostReg);
|
|
397
|
+
const protocol = host_arr[1];
|
|
398
|
+
const host = host_arr[3];
|
|
399
|
+
// 主域部分
|
|
400
|
+
const origin = protocol + host;
|
|
401
|
+
// 剩下部分
|
|
402
|
+
_url = `https://www.echoapi.cn${_url.substring(origin.length)}`;
|
|
403
|
+
let urls = {};
|
|
404
|
+
try {
|
|
405
|
+
urls = new URL(_url);
|
|
689
406
|
}
|
|
690
|
-
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
407
|
+
catch (_a) {
|
|
408
|
+
const http_url = `https://www.echoapi.cn${_url.substring(origin.length)}`;
|
|
409
|
+
const a = document.createElement("a");
|
|
410
|
+
a.href = http_url;
|
|
411
|
+
urls = {
|
|
412
|
+
source: _url,
|
|
413
|
+
href: a.href,
|
|
414
|
+
protocol: a.protocol,
|
|
415
|
+
host: a.hostname,
|
|
416
|
+
hostname: a.hostname,
|
|
417
|
+
port: a.port,
|
|
418
|
+
origin: a.origin,
|
|
419
|
+
search: a.search,
|
|
420
|
+
pathname: a.pathname,
|
|
421
|
+
// eslint-disable-next-line no-useless-escape
|
|
422
|
+
file: (a.pathname.match(/\/([^\/?#]+)$/i) || ["", ""])[1],
|
|
423
|
+
hash: a.hash,
|
|
424
|
+
};
|
|
707
425
|
}
|
|
708
|
-
return
|
|
426
|
+
return urls;
|
|
709
427
|
};
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
refId = refPath.split('/').pop() || '';
|
|
728
|
-
}
|
|
729
|
-
if (refId &&
|
|
730
|
-
lodash.has(schemaMap, refId) &&
|
|
731
|
-
!lodash.isEqual(startSchema || originSchema, (_a = schemaMap[refId]) === null || _a === void 0 ? void 0 : _a.schema)) {
|
|
732
|
-
const mapValue = schemaMap[refId];
|
|
733
|
-
if (mapValue && (mapValue === null || mapValue === void 0 ? void 0 : mapValue.name)) {
|
|
734
|
-
// 暂时没找到多ref引用的方案 先直接导出数据
|
|
735
|
-
// pre[mapValue?.name] = {
|
|
736
|
-
// $ref: mapValue?.path,
|
|
737
|
-
// };
|
|
738
|
-
let mapSchema = mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema;
|
|
739
|
-
if (lodash.has(mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema, 'x-schema-refs')) {
|
|
740
|
-
if (deepCount > MAX_DEEP_COUNT) {
|
|
741
|
-
mapSchema = mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema;
|
|
742
|
-
}
|
|
743
|
-
else {
|
|
744
|
-
mapSchema = deepModelRef(mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema, schemaMap, startSchema || originSchema, ++deepCount);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
pre = Object.assign(Object.assign({}, pre), ((mapSchema === null || mapSchema === void 0 ? void 0 : mapSchema.properties) || {}));
|
|
748
|
-
}
|
|
749
|
-
if (lodash.isEqual(startSchema || originSchema, (_b = schemaMap[refId]) === null || _b === void 0 ? void 0 : _b.schema)) {
|
|
750
|
-
pre = {};
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
return pre;
|
|
754
|
-
}, properties);
|
|
428
|
+
// 根据url生成新的restful数组
|
|
429
|
+
const genRestfulByUrl = (url, oldParameter, key = "key") => {
|
|
430
|
+
const restfulList = [];
|
|
431
|
+
// 自动拼接url http://
|
|
432
|
+
if (!isURL(url)) {
|
|
433
|
+
url = `http://${url}`;
|
|
434
|
+
}
|
|
435
|
+
const urlObj = createUrl(url);
|
|
436
|
+
const paths = urlObj.pathname.split('/');
|
|
437
|
+
lodash.forEach(paths, (pathsItem) => {
|
|
438
|
+
if (pathsItem.substring(0, 1) === ":" && pathsItem.length > 1) {
|
|
439
|
+
let obj = null;
|
|
440
|
+
const oldIndex = lodash.findIndex(oldParameter, {
|
|
441
|
+
[key]: pathsItem.substring(1, pathsItem.length),
|
|
442
|
+
});
|
|
443
|
+
if (oldIndex !== -1) {
|
|
444
|
+
obj = oldParameter[oldIndex];
|
|
755
445
|
}
|
|
446
|
+
restfulList.push({
|
|
447
|
+
param_id: (obj === null || obj === void 0 ? void 0 : obj.param_id) || apipostTools.snowflakeId(),
|
|
448
|
+
field_type: (obj === null || obj === void 0 ? void 0 : obj.field_type) || 'string',
|
|
449
|
+
is_checked: 1,
|
|
450
|
+
key: pathsItem.substring(1, pathsItem.length),
|
|
451
|
+
not_null: 1,
|
|
452
|
+
value: (obj === null || obj === void 0 ? void 0 : obj.value) || '',
|
|
453
|
+
description: (obj === null || obj === void 0 ? void 0 : obj.description) || '',
|
|
454
|
+
schema: (obj === null || obj === void 0 ? void 0 : obj.schema) || {}
|
|
455
|
+
});
|
|
756
456
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
(
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
if (
|
|
770
|
-
|
|
771
|
-
}
|
|
772
|
-
else {
|
|
773
|
-
pre[key] = deepModelRef(schema === null || schema === void 0 ? void 0 : schema.properties[key], schemaMap, startSchema || originSchema, ++deepCount);
|
|
457
|
+
});
|
|
458
|
+
const regex = /(?<!{){([^{}]+)}(?!})/g;
|
|
459
|
+
try {
|
|
460
|
+
const matches = url.match(regex);
|
|
461
|
+
if (isArray(matches) && matches.length > 0) {
|
|
462
|
+
lodash.forEach(matches, (matchesItem) => {
|
|
463
|
+
if (matchesItem.length > 0) {
|
|
464
|
+
matchesItem = matchesItem.replace(/^{|}$/g, "");
|
|
465
|
+
let obj = null;
|
|
466
|
+
const oldIndex = lodash.findIndex(oldParameter, {
|
|
467
|
+
[key]: matchesItem,
|
|
468
|
+
});
|
|
469
|
+
if (oldIndex !== -1) {
|
|
470
|
+
obj = oldParameter[oldIndex];
|
|
774
471
|
}
|
|
472
|
+
restfulList.push({
|
|
473
|
+
param_id: (obj === null || obj === void 0 ? void 0 : obj.param_id) || apipostTools.snowflakeId(),
|
|
474
|
+
field_type: (obj === null || obj === void 0 ? void 0 : obj.field_type) || 'string',
|
|
475
|
+
is_checked: 1,
|
|
476
|
+
key: matchesItem,
|
|
477
|
+
not_null: 1,
|
|
478
|
+
value: (obj === null || obj === void 0 ? void 0 : obj.value) || '',
|
|
479
|
+
description: (obj === null || obj === void 0 ? void 0 : obj.description) || '',
|
|
480
|
+
schema: (obj === null || obj === void 0 ? void 0 : obj.schema) || {}
|
|
481
|
+
});
|
|
775
482
|
}
|
|
776
|
-
|
|
777
|
-
}, {});
|
|
778
|
-
}
|
|
779
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' && lodash.has(schema, 'items')) {
|
|
780
|
-
if (lodash.has(schema === null || schema === void 0 ? void 0 : schema.items, 'properties') &&
|
|
781
|
-
Object.prototype.toString.call((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.properties) === '[object Object]') {
|
|
782
|
-
if (deepCount <= MAX_DEEP_COUNT) {
|
|
783
|
-
schema.items = deepModelRef(schema === null || schema === void 0 ? void 0 : schema.items, schemaMap, startSchema || originSchema, ++deepCount);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
483
|
+
});
|
|
786
484
|
}
|
|
787
|
-
// 处理数组的引用
|
|
788
|
-
schema === null || schema === void 0 ? true : delete schema['x-schema-orders'];
|
|
789
|
-
schema === null || schema === void 0 ? true : delete schema['x-schema-refs'];
|
|
790
|
-
return schema;
|
|
791
|
-
}
|
|
792
|
-
catch (err) {
|
|
793
|
-
console.log(err.message, "deepModelRef error");
|
|
794
|
-
return originSchema;
|
|
795
485
|
}
|
|
486
|
+
catch (error) { }
|
|
487
|
+
return restfulList;
|
|
796
488
|
};
|
|
797
|
-
|
|
798
|
-
//
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
//
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
// if (lonely && hasInvPath) {
|
|
831
|
-
// modelObj.$ref = modelPath;
|
|
832
|
-
// } else {
|
|
833
|
-
// refArr.forEach((item: any) => {
|
|
834
|
-
// const modelObjItem = modelsObj?.[value?.[item]?.ref];
|
|
835
|
-
// modelPath = splicedPath(modelObjItem?.modelPath, version);
|
|
836
|
-
// modelObj.properties["$ref"] = modelPath;
|
|
837
|
-
// });
|
|
838
|
-
// }
|
|
839
|
-
// }
|
|
840
|
-
// }
|
|
841
|
-
// }
|
|
842
|
-
// // 如果属性是一个对象,就递归查找
|
|
843
|
-
// else if (
|
|
844
|
-
// Object.prototype.toString.call(value) === "[object Object]" &&
|
|
845
|
-
// value !== null
|
|
846
|
-
// ) {
|
|
847
|
-
// modelObj[key] = deepHandleModelRef(value, modelsObj, version);
|
|
848
|
-
// }
|
|
849
|
-
// }
|
|
850
|
-
// }
|
|
851
|
-
// return result;
|
|
852
|
-
// };
|
|
853
|
-
const removeQuery = (url) => {
|
|
854
|
-
let path = url;
|
|
489
|
+
const removePTags = (str) => {
|
|
490
|
+
// 使用正则表达式替换<p>和</p>标签为空字符串
|
|
491
|
+
return str.replace(/<\/?[^>]+(>|$)/g, "");
|
|
492
|
+
};
|
|
493
|
+
const yapiGenRestfulByUrl = (url, oldParameter) => {
|
|
494
|
+
const restfulList = [];
|
|
495
|
+
// 自动拼接url http://
|
|
496
|
+
if (!isURL(url)) {
|
|
497
|
+
url = `http://${url}`;
|
|
498
|
+
}
|
|
499
|
+
const urlObj = createUrl(url);
|
|
500
|
+
const paths = urlObj.pathname.split("/");
|
|
501
|
+
lodash.forEach(paths, (pathsItem) => {
|
|
502
|
+
if (pathsItem.substring(0, 1) === ":" && pathsItem.length > 1) {
|
|
503
|
+
let obj = null;
|
|
504
|
+
const oldIndex = lodash.findIndex(oldParameter, {
|
|
505
|
+
name: pathsItem.substring(1, pathsItem.length),
|
|
506
|
+
});
|
|
507
|
+
if (oldIndex !== -1) {
|
|
508
|
+
obj = oldParameter[oldIndex];
|
|
509
|
+
}
|
|
510
|
+
restfulList.push({
|
|
511
|
+
param_id: (obj === null || obj === void 0 ? void 0 : obj.param_id) || apipostTools.snowflakeId(),
|
|
512
|
+
field_type: "String",
|
|
513
|
+
is_checked: 1,
|
|
514
|
+
key: pathsItem.substring(1, pathsItem.length),
|
|
515
|
+
not_null: 1,
|
|
516
|
+
value: (obj === null || obj === void 0 ? void 0 : obj.example) || "",
|
|
517
|
+
description: (obj === null || obj === void 0 ? void 0 : obj.desc) || "",
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
const regex = /(?<!{){([^{}]+)}(?!})/g;
|
|
855
522
|
try {
|
|
856
|
-
const
|
|
857
|
-
|
|
523
|
+
const matches = url.match(regex);
|
|
524
|
+
if (isArray(matches) && matches.length > 0) {
|
|
525
|
+
lodash.forEach(matches, (matchesItem) => {
|
|
526
|
+
if (matchesItem.length > 0) {
|
|
527
|
+
matchesItem = matchesItem.replace(/^{|}$/g, "");
|
|
528
|
+
let obj = null;
|
|
529
|
+
const oldIndex = lodash.findIndex(oldParameter, {
|
|
530
|
+
name: matchesItem,
|
|
531
|
+
});
|
|
532
|
+
if (oldIndex !== -1) {
|
|
533
|
+
obj = oldParameter[oldIndex];
|
|
534
|
+
}
|
|
535
|
+
restfulList.push({
|
|
536
|
+
param_id: (obj === null || obj === void 0 ? void 0 : obj.param_id) || apipostTools.snowflakeId(),
|
|
537
|
+
field_type: "String",
|
|
538
|
+
is_checked: 1,
|
|
539
|
+
key: matchesItem,
|
|
540
|
+
not_null: 1,
|
|
541
|
+
value: (obj === null || obj === void 0 ? void 0 : obj.example) || "",
|
|
542
|
+
description: (obj === null || obj === void 0 ? void 0 : obj.desc) || "",
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
}
|
|
858
547
|
}
|
|
859
548
|
catch (error) { }
|
|
860
|
-
return
|
|
549
|
+
return restfulList;
|
|
861
550
|
};
|
|
862
|
-
const
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
551
|
+
const fixUrlPath = (url) => {
|
|
552
|
+
try {
|
|
553
|
+
const index = url.indexOf("://");
|
|
554
|
+
let path;
|
|
555
|
+
let protocolAndDomain = "";
|
|
556
|
+
if (index === -1) {
|
|
557
|
+
path = url;
|
|
866
558
|
}
|
|
867
559
|
else {
|
|
868
|
-
|
|
560
|
+
// 分开协议和路径部分
|
|
561
|
+
protocolAndDomain = url.slice(0, index + 3);
|
|
562
|
+
path = url.slice(index + 3);
|
|
869
563
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
564
|
+
// 修正路径中的 '//'
|
|
565
|
+
const fixedPath = path.replace(/\/\/+/g, "/");
|
|
566
|
+
// 拼接返回
|
|
567
|
+
return `${protocolAndDomain}${fixedPath}`;
|
|
568
|
+
}
|
|
569
|
+
catch (err) {
|
|
570
|
+
return url;
|
|
873
571
|
}
|
|
874
|
-
return path;
|
|
875
572
|
};
|
|
876
|
-
const
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
const obj = JSON.parse(objStr);
|
|
880
|
-
for (const key in obj) {
|
|
881
|
-
if (lodash.isPlainObject(obj[key])) {
|
|
882
|
-
ret[key] = {
|
|
883
|
-
type: "object",
|
|
884
|
-
properties: generateProperties(JSON.stringify(obj[key])),
|
|
885
|
-
};
|
|
886
|
-
}
|
|
887
|
-
else if (obj[key]) {
|
|
888
|
-
ret[key] = {
|
|
889
|
-
type: typeof obj[key] === "number" ? "integer" : typeof obj[key],
|
|
890
|
-
example: obj[key],
|
|
891
|
-
};
|
|
892
|
-
}
|
|
893
|
-
}
|
|
573
|
+
const anyToString = (desc) => {
|
|
574
|
+
if (lodash.isString(desc)) {
|
|
575
|
+
return desc;
|
|
894
576
|
}
|
|
895
|
-
|
|
896
|
-
|
|
577
|
+
if (lodash.isNumber(desc)) {
|
|
578
|
+
return desc.toString();
|
|
579
|
+
}
|
|
580
|
+
if (lodash.isPlainObject(desc) || isArray(desc)) {
|
|
581
|
+
return JSON.stringify(desc);
|
|
582
|
+
}
|
|
583
|
+
return String(desc);
|
|
897
584
|
};
|
|
898
|
-
const
|
|
899
|
-
|
|
585
|
+
const completionMethod = (method) => {
|
|
586
|
+
if (!method || !lodash.isString(method))
|
|
587
|
+
return "GET";
|
|
588
|
+
if (API_METHODS.includes(method === null || method === void 0 ? void 0 : method.toUpperCase())) {
|
|
589
|
+
return method === null || method === void 0 ? void 0 : method.toUpperCase();
|
|
590
|
+
}
|
|
591
|
+
return method;
|
|
900
592
|
};
|
|
901
|
-
|
|
593
|
+
// 根据query数组生成新的url
|
|
594
|
+
const genUrlByQuery = (url, parameter, query_add_equal = 1) => {
|
|
902
595
|
var _a;
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
596
|
+
let paramsStr = "";
|
|
597
|
+
let newUrl = url || "";
|
|
598
|
+
const handleEncode = (value = "") => {
|
|
599
|
+
let _value = lodash.cloneDeep(value);
|
|
600
|
+
try {
|
|
601
|
+
// 将#符号encode
|
|
602
|
+
_value = _value.replace(/#/g, encodeURIComponent("#"));
|
|
603
|
+
// 将&符号encode
|
|
604
|
+
_value = _value.replace(/&/g, encodeURIComponent("&"));
|
|
906
605
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
in: type,
|
|
914
|
-
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
915
|
-
required: (item === null || item === void 0 ? void 0 : item.not_null) === 1,
|
|
916
|
-
example: String((item === null || item === void 0 ? void 0 : item.value) || ""),
|
|
917
|
-
schema: Object.assign({ type: (_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase() }, ((item === null || item === void 0 ? void 0 : item.schema) || {})),
|
|
918
|
-
});
|
|
919
|
-
}
|
|
606
|
+
catch (e) { }
|
|
607
|
+
return _value;
|
|
608
|
+
};
|
|
609
|
+
lodash.forEach(parameter, (item) => {
|
|
610
|
+
if (item.key && lodash.isEqual(item.is_checked, 1)) {
|
|
611
|
+
paramsStr += `${paramsStr ? "&" : ""}${handleEncode(item.key)}${lodash.isEqual(query_add_equal, -1) && !item.value ? "" : "="}${handleEncode(item.value)}`;
|
|
920
612
|
}
|
|
921
|
-
}
|
|
613
|
+
});
|
|
614
|
+
// NOTE 原地址有hash的话,需拼接回去
|
|
615
|
+
newUrl = `${lodash.head(newUrl.split("?"))}${paramsStr ? "?" : ""}${paramsStr}${((_a = urlParse__default["default"](newUrl)) === null || _a === void 0 ? void 0 : _a.hash) || ""}`;
|
|
616
|
+
return newUrl;
|
|
922
617
|
};
|
|
923
|
-
const
|
|
924
|
-
if (lodash.
|
|
925
|
-
|
|
926
|
-
pathItem.parameters = [];
|
|
927
|
-
}
|
|
928
|
-
const mode = MODE_TYPE[body === null || body === void 0 ? void 0 : body.mode];
|
|
929
|
-
if (lodash.isString(mode) && mode.length > 0) {
|
|
930
|
-
if ([
|
|
931
|
-
"application/json",
|
|
932
|
-
"application/xml",
|
|
933
|
-
"application/javascript",
|
|
934
|
-
"text/plain",
|
|
935
|
-
"text/html",
|
|
936
|
-
].includes(mode)) {
|
|
937
|
-
let obj = {
|
|
938
|
-
in: "body",
|
|
939
|
-
name: "body",
|
|
940
|
-
description: "",
|
|
941
|
-
schema: deepModelRef((body === null || body === void 0 ? void 0 : body.raw_schema) || {
|
|
942
|
-
type: 'object'
|
|
943
|
-
}, modelsObj),
|
|
944
|
-
type: "string",
|
|
945
|
-
example: (body === null || body === void 0 ? void 0 : body.raw) || "",
|
|
946
|
-
};
|
|
947
|
-
pathItem.parameters.push(obj);
|
|
948
|
-
}
|
|
949
|
-
else if (["multipart/form-data", "application/x-www-form-urlencoded"].includes(mode)) {
|
|
950
|
-
const parameter = (body === null || body === void 0 ? void 0 : body.parameter) || [];
|
|
951
|
-
if (lodash.isArray(parameter) && parameter.length > 0) {
|
|
952
|
-
parameter.forEach((item) => {
|
|
953
|
-
if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
|
|
954
|
-
item.key.length > 0 &&
|
|
955
|
-
(!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
|
|
956
|
-
pathItem.parameters.push({
|
|
957
|
-
in: "formData",
|
|
958
|
-
name: "body",
|
|
959
|
-
type: "string",
|
|
960
|
-
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
961
|
-
default: (item === null || item === void 0 ? void 0 : item.value) || "",
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
}
|
|
618
|
+
const getSubstring = (str, length) => {
|
|
619
|
+
if (lodash.isString(str)) {
|
|
620
|
+
return str.substring(0, length);
|
|
968
621
|
}
|
|
622
|
+
return str;
|
|
969
623
|
};
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
pathItem.requestBody.content[mode] = {
|
|
982
|
-
'x-query': (m === null || m === void 0 ? void 0 : m.query) || '',
|
|
983
|
-
'x-variables': (m === null || m === void 0 ? void 0 : m.variables) || '',
|
|
984
|
-
'x-summary': (m === null || m === void 0 ? void 0 : m.name) || '',
|
|
985
|
-
'x-response': {
|
|
986
|
-
'x-mode': ((_a = m === null || m === void 0 ? void 0 : m.response) === null || _a === void 0 ? void 0 : _a.mode) || '',
|
|
987
|
-
example: ((_b = m === null || m === void 0 ? void 0 : m.response) === null || _b === void 0 ? void 0 : _b.raw) || "",
|
|
988
|
-
schema: deepModelRef(((_c = m === null || m === void 0 ? void 0 : m.response) === null || _c === void 0 ? void 0 : _c.raw_schema) || {
|
|
989
|
-
type: "object",
|
|
990
|
-
}, modelsObj),
|
|
991
|
-
}
|
|
992
|
-
};
|
|
993
|
-
});
|
|
624
|
+
|
|
625
|
+
const getApipostMode = (mode) => {
|
|
626
|
+
let apipostMode = 'none';
|
|
627
|
+
if (mode == 'multipart/form-data') {
|
|
628
|
+
apipostMode = 'form-data';
|
|
629
|
+
}
|
|
630
|
+
else if (mode == 'application/x-www-form-urlencoded') {
|
|
631
|
+
apipostMode = 'urlencoded';
|
|
632
|
+
}
|
|
633
|
+
else if (mode == 'application/octet-stream') {
|
|
634
|
+
apipostMode = 'binary';
|
|
994
635
|
}
|
|
636
|
+
else if (mode && mode != undefined) {
|
|
637
|
+
apipostMode = 'json';
|
|
638
|
+
}
|
|
639
|
+
return apipostMode;
|
|
995
640
|
};
|
|
996
|
-
const
|
|
997
|
-
let
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
return `${description}\n${t('tcpMethodMessage', {
|
|
1001
|
-
direction: (rules === null || rules === void 0 ? void 0 : rules.fill_type) == 'left' ? t('left') : (rules === null || rules === void 0 ? void 0 : rules.fill_type) == 'right' ? t('right') : '',
|
|
1002
|
-
size: rules === null || rules === void 0 ? void 0 : rules.length,
|
|
1003
|
-
str: (rules === null || rules === void 0 ? void 0 : rules.content_type) == 'common' ? RULE_TYPES[rules === null || rules === void 0 ? void 0 : rules.common] : rules === null || rules === void 0 ? void 0 : rules.custom
|
|
1004
|
-
})}`;
|
|
641
|
+
const getSwaggerMode = (mode) => {
|
|
642
|
+
let swaggerMode = '';
|
|
643
|
+
if (mode == 'form-data') {
|
|
644
|
+
swaggerMode = 'multipart/form-data';
|
|
1005
645
|
}
|
|
1006
|
-
else if (mode == '
|
|
1007
|
-
|
|
1008
|
-
str: RULE_TYPES_ICON[rules === null || rules === void 0 ? void 0 : rules.delimiter]
|
|
1009
|
-
})}`;
|
|
646
|
+
else if (mode == 'urlencoded') {
|
|
647
|
+
swaggerMode = 'application/x-www-form-urlencoded';
|
|
1010
648
|
}
|
|
1011
|
-
|
|
649
|
+
else if (mode == 'binary') {
|
|
650
|
+
swaggerMode = 'application/octet-stream';
|
|
651
|
+
}
|
|
652
|
+
else if (mode && mode != undefined) {
|
|
653
|
+
swaggerMode = 'application/json';
|
|
654
|
+
}
|
|
655
|
+
return swaggerMode;
|
|
1012
656
|
};
|
|
1013
|
-
const
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
657
|
+
const handleBodyJsonSchema = (schema, raw_para, pre = '', requiredArr = [], propName = '') => {
|
|
658
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
659
|
+
requiredArr = (requiredArr && Array.isArray(requiredArr)) ? requiredArr : [];
|
|
660
|
+
let type = ((schema === null || schema === void 0 ? void 0 : schema.type) && lodash.isString(schema === null || schema === void 0 ? void 0 : schema.type)) ? schema.type.toLowerCase() : 'string';
|
|
661
|
+
if (type === "object") {
|
|
662
|
+
let properties = ((_a = schema === null || schema === void 0 ? void 0 : schema.additionalProperties) === null || _a === void 0 ? void 0 : _a.properties) || (schema === null || schema === void 0 ? void 0 : schema.properties) || {};
|
|
663
|
+
const example = {};
|
|
664
|
+
for (const key in properties) {
|
|
665
|
+
if (lodash.has(properties, key)) {
|
|
666
|
+
const item = properties[key];
|
|
667
|
+
example[key] = handleBodyJsonSchema(item, raw_para, pre ? `${pre}.${key}` : `${key}`, schema === null || schema === void 0 ? void 0 : schema.required, key);
|
|
668
|
+
}
|
|
1019
669
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
670
|
+
if (pre) {
|
|
671
|
+
raw_para.push({
|
|
672
|
+
key: `${pre}`,
|
|
673
|
+
value: (schema === null || schema === void 0 ? void 0 : schema.example) || (schema === null || schema === void 0 ? void 0 : schema.default) || "",
|
|
674
|
+
description: String((schema === null || schema === void 0 ? void 0 : schema.description) || ''),
|
|
675
|
+
not_null: (requiredArr === null || requiredArr === void 0 ? void 0 : requiredArr.find(it => it == propName)) ? 1 : -1,
|
|
676
|
+
field_type: type ? type.charAt(0).toUpperCase() + type.slice(1) : "String",
|
|
677
|
+
is_checked: 1,
|
|
678
|
+
param_id: apipostTools.snowflakeId(),
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
return example;
|
|
682
|
+
}
|
|
683
|
+
else if (type === "array") {
|
|
684
|
+
const example = [];
|
|
685
|
+
// raw_para.push({
|
|
686
|
+
// key: `${pre}`,
|
|
687
|
+
// value: "",
|
|
688
|
+
// description: String(schema?.description || ''),
|
|
689
|
+
// not_null: requiredArr?.find(it => it == propName) ? 1 : -1,
|
|
690
|
+
// field_type: "Array",
|
|
691
|
+
// is_checked: 1,
|
|
692
|
+
// param_id: snowflakeId(),
|
|
693
|
+
// });
|
|
694
|
+
let itemsType = ((_d = (_c = (_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.oneOf) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.type) || ((_e = schema === null || schema === void 0 ? void 0 : schema.items) === null || _e === void 0 ? void 0 : _e.type) || 'string';
|
|
695
|
+
if (itemsType === 'object') {
|
|
696
|
+
let properties = ((_h = (_g = (_f = schema === null || schema === void 0 ? void 0 : schema.items) === null || _f === void 0 ? void 0 : _f.oneOf) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.properties) || ((_j = schema === null || schema === void 0 ? void 0 : schema.items) === null || _j === void 0 ? void 0 : _j.properties) || ((_k = schema === null || schema === void 0 ? void 0 : schema.additionalProperties) === null || _k === void 0 ? void 0 : _k.properties) || (schema === null || schema === void 0 ? void 0 : schema.properties) || {};
|
|
697
|
+
let required = ((_o = (_m = (_l = schema === null || schema === void 0 ? void 0 : schema.items) === null || _l === void 0 ? void 0 : _l.oneOf) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.required) || ((_p = schema === null || schema === void 0 ? void 0 : schema.items) === null || _p === void 0 ? void 0 : _p.required) || ((_q = schema === null || schema === void 0 ? void 0 : schema.additionalProperties) === null || _q === void 0 ? void 0 : _q.required) || (schema === null || schema === void 0 ? void 0 : schema.required) || [];
|
|
698
|
+
let obj = {};
|
|
699
|
+
for (const key in properties) {
|
|
700
|
+
if (lodash.has(properties, key)) {
|
|
701
|
+
const item = properties[key];
|
|
702
|
+
obj[key] = handleBodyJsonSchema(item, raw_para, pre ? `${pre}.${key}` : `${key}`, required, key);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
example.push(obj);
|
|
706
|
+
}
|
|
707
|
+
else if (itemsType === "integer") {
|
|
708
|
+
let value = ((_t = (_s = (_r = schema === null || schema === void 0 ? void 0 : schema.items) === null || _r === void 0 ? void 0 : _r.oneOf) === null || _s === void 0 ? void 0 : _s[0]) === null || _t === void 0 ? void 0 : _t.example) || ((_u = schema === null || schema === void 0 ? void 0 : schema.items) === null || _u === void 0 ? void 0 : _u.example) || 0;
|
|
709
|
+
// console.log(value,"valuevalue");
|
|
710
|
+
if (Object.prototype.toString.call(raw_para) === '[object Array]') {
|
|
711
|
+
raw_para.push({
|
|
712
|
+
key: `${pre}.0`,
|
|
713
|
+
value: value ? String(value) : '',
|
|
714
|
+
description: String((schema === null || schema === void 0 ? void 0 : schema.description) || ''),
|
|
715
|
+
not_null: (requiredArr === null || requiredArr === void 0 ? void 0 : requiredArr.find(it => it == propName)) ? 1 : -1,
|
|
716
|
+
field_type: type ? type.charAt(0).toUpperCase() + type.slice(1) : "String",
|
|
717
|
+
type: "String",
|
|
718
|
+
is_checked: 1,
|
|
719
|
+
param_id: apipostTools.snowflakeId(),
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
example.push(value);
|
|
1042
723
|
}
|
|
1043
724
|
else {
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
725
|
+
let value = ((_x = (_w = (_v = schema === null || schema === void 0 ? void 0 : schema.items) === null || _v === void 0 ? void 0 : _v.oneOf) === null || _w === void 0 ? void 0 : _w[0]) === null || _x === void 0 ? void 0 : _x.example) || ((_y = schema === null || schema === void 0 ? void 0 : schema.items) === null || _y === void 0 ? void 0 : _y.example) || '';
|
|
726
|
+
if (Object.prototype.toString.call(raw_para) === '[object Array]') {
|
|
727
|
+
raw_para.push({
|
|
728
|
+
key: `${pre}.0`,
|
|
729
|
+
value: value || '',
|
|
730
|
+
description: String((schema === null || schema === void 0 ? void 0 : schema.description) || ''),
|
|
731
|
+
not_null: (requiredArr === null || requiredArr === void 0 ? void 0 : requiredArr.find(it => it == propName)) ? 1 : -1,
|
|
732
|
+
field_type: type ? type.charAt(0).toUpperCase() + type.slice(1) : "String",
|
|
733
|
+
type: "String",
|
|
734
|
+
is_checked: 1,
|
|
735
|
+
param_id: apipostTools.snowflakeId(),
|
|
736
|
+
});
|
|
1052
737
|
}
|
|
738
|
+
example.push(value);
|
|
1053
739
|
}
|
|
740
|
+
return example;
|
|
1054
741
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
742
|
+
else if (type === "integer") {
|
|
743
|
+
if (Object.prototype.toString.call(raw_para) === '[object Array]') {
|
|
744
|
+
raw_para.push({
|
|
745
|
+
key: `${pre}`,
|
|
746
|
+
value: ((schema === null || schema === void 0 ? void 0 : schema.example) || (schema === null || schema === void 0 ? void 0 : schema.default)) ? String((schema === null || schema === void 0 ? void 0 : schema.example) || (schema === null || schema === void 0 ? void 0 : schema.default)) : '',
|
|
747
|
+
description: String((schema === null || schema === void 0 ? void 0 : schema.description) || ''),
|
|
748
|
+
not_null: (requiredArr === null || requiredArr === void 0 ? void 0 : requiredArr.find(it => it == propName)) ? 1 : -1,
|
|
749
|
+
field_type: type ? type.charAt(0).toUpperCase() + type.slice(1) : "String",
|
|
750
|
+
is_checked: 1,
|
|
751
|
+
param_id: apipostTools.snowflakeId(),
|
|
752
|
+
});
|
|
1062
753
|
}
|
|
1063
|
-
|
|
1064
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1065
|
-
const mode = `x-${m === null || m === void 0 ? void 0 : m.param_id}`;
|
|
1066
|
-
pathItem.requestBody.content[mode] = {
|
|
1067
|
-
'x-mode': ((_a = m === null || m === void 0 ? void 0 : m.request) === null || _a === void 0 ? void 0 : _a.mode) || '',
|
|
1068
|
-
'x-summary': (m === null || m === void 0 ? void 0 : m.name) || '',
|
|
1069
|
-
schema: deepModelRef(((_b = m === null || m === void 0 ? void 0 : m.request) === null || _b === void 0 ? void 0 : _b.raw_schema) || {
|
|
1070
|
-
type: "object",
|
|
1071
|
-
}, modelsObj),
|
|
1072
|
-
example: ((_c = m === null || m === void 0 ? void 0 : m.request) === null || _c === void 0 ? void 0 : _c.raw) || "",
|
|
1073
|
-
'x-response': {
|
|
1074
|
-
'x-mode': ((_d = m === null || m === void 0 ? void 0 : m.response) === null || _d === void 0 ? void 0 : _d.mode) || '',
|
|
1075
|
-
example: ((_e = m === null || m === void 0 ? void 0 : m.response) === null || _e === void 0 ? void 0 : _e.raw) || "",
|
|
1076
|
-
schema: deepModelRef(((_f = m === null || m === void 0 ? void 0 : m.response) === null || _f === void 0 ? void 0 : _f.raw_schema) || {
|
|
1077
|
-
type: "object",
|
|
1078
|
-
}, modelsObj),
|
|
1079
|
-
}
|
|
1080
|
-
};
|
|
1081
|
-
});
|
|
754
|
+
return (schema === null || schema === void 0 ? void 0 : schema.example) || (schema === null || schema === void 0 ? void 0 : schema.default) || 0;
|
|
1082
755
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
example: raw || '',
|
|
1097
|
-
},
|
|
1098
|
-
},
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
});
|
|
756
|
+
else {
|
|
757
|
+
if (Object.prototype.toString.call(raw_para) === '[object Array]') {
|
|
758
|
+
raw_para.push({
|
|
759
|
+
key: `${pre}`,
|
|
760
|
+
value: (schema === null || schema === void 0 ? void 0 : schema.example) || (schema === null || schema === void 0 ? void 0 : schema.default) || "",
|
|
761
|
+
description: String((schema === null || schema === void 0 ? void 0 : schema.description) || ''),
|
|
762
|
+
not_null: (requiredArr === null || requiredArr === void 0 ? void 0 : requiredArr.find(it => it == propName)) ? 1 : -1,
|
|
763
|
+
field_type: type ? type.charAt(0).toUpperCase() + type.slice(1) : "String",
|
|
764
|
+
is_checked: 1,
|
|
765
|
+
param_id: apipostTools.snowflakeId(),
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
return (schema === null || schema === void 0 ? void 0 : schema.example) || (schema === null || schema === void 0 ? void 0 : schema.default) || "";
|
|
1102
769
|
}
|
|
1103
|
-
return temp_responses;
|
|
1104
770
|
};
|
|
1105
|
-
const
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
};
|
|
1127
|
-
}
|
|
1128
|
-
else if (["multipart/form-data", "application/x-www-form-urlencoded"].includes(mode)) {
|
|
1129
|
-
const parameter = (body === null || body === void 0 ? void 0 : body.parameter) || [];
|
|
1130
|
-
if (lodash.isArray(parameter) && parameter.length > 0) {
|
|
1131
|
-
pathItem.requestBody.content[mode] = {
|
|
1132
|
-
schema: {
|
|
1133
|
-
type: "object",
|
|
1134
|
-
properties: parameter.reduce((lastData, item) => {
|
|
1135
|
-
var _a;
|
|
1136
|
-
if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
|
|
1137
|
-
item.key.length > 0 &&
|
|
1138
|
-
(!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
|
|
1139
|
-
lastData[item.key] = Object.assign({ type: ((_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || 'string', description: (item === null || item === void 0 ? void 0 : item.description) || "", example: (item === null || item === void 0 ? void 0 : item.value) || "" }, (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.schema) ? item.schema : {}));
|
|
1140
|
-
}
|
|
1141
|
-
return lastData;
|
|
1142
|
-
}, {})
|
|
771
|
+
const replaceRef = (schemaObj) => {
|
|
772
|
+
var _a;
|
|
773
|
+
try {
|
|
774
|
+
for (const key in schemaObj) {
|
|
775
|
+
const value = schemaObj[key];
|
|
776
|
+
// 如果当前属性的值是一个对象,则递归遍历该对象
|
|
777
|
+
if (typeof value === 'object' && value !== null) {
|
|
778
|
+
// 查找并替换 insAppInfo 对象
|
|
779
|
+
if (lodash.has(value, 'ref') || lodash.has(value, '$ref')) {
|
|
780
|
+
let newIuid = apipostTools.snowflakeId();
|
|
781
|
+
if ((value === null || value === void 0 ? void 0 : value.ref) && value.ref.startsWith('http://localhost:8000/')) {
|
|
782
|
+
const index = (_a = value.ref) === null || _a === void 0 ? void 0 : _a.indexOf('#');
|
|
783
|
+
if (index !== -1) {
|
|
784
|
+
value.ref = value.ref.substring(index);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
schemaObj[key] = {
|
|
788
|
+
['x-schema-refs']: {
|
|
789
|
+
[newIuid]: {
|
|
790
|
+
$ref: (value === null || value === void 0 ? void 0 : value.ref) || (value === null || value === void 0 ? void 0 : value['$ref'])
|
|
791
|
+
},
|
|
1143
792
|
},
|
|
793
|
+
properties: {},
|
|
794
|
+
['x-schema-orders']: [newIuid],
|
|
795
|
+
type: "object"
|
|
1144
796
|
};
|
|
797
|
+
continue;
|
|
1145
798
|
}
|
|
799
|
+
replaceRef(value);
|
|
1146
800
|
}
|
|
1147
801
|
}
|
|
1148
802
|
}
|
|
1149
|
-
|
|
1150
|
-
(pathItem === null || pathItem === void 0 ? void 0 : pathItem.requestBody) && delete pathItem.requestBody;
|
|
1151
|
-
}
|
|
803
|
+
catch (error) { }
|
|
1152
804
|
};
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
805
|
+
const swaggerSchema2apipostSchema = (schemaObj) => {
|
|
806
|
+
var _a;
|
|
807
|
+
let jsonSchema = {};
|
|
808
|
+
try {
|
|
809
|
+
// x-apifox-orders 2 ECHOAPI_ORDERS x-apifox-refs 2 ECHOAPI_REFS $ref 2 ref x-apifox-overrides 2 ECHOAPI_OVERRIDES
|
|
810
|
+
let jsonSchemaStr = JSON.stringify(schemaObj);
|
|
811
|
+
// 替换 x-apifox-orders 为 APIPOST_ORDERS
|
|
812
|
+
jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-orders\"/g, '\"x-schema-orders\"');
|
|
813
|
+
// 替换 x-apifox-refs 为 APIPOST_REFS
|
|
814
|
+
jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-refs\"/g, '\"x-schema-refs\"');
|
|
815
|
+
// 替换 $ref 为 ref
|
|
816
|
+
jsonSchemaStr = jsonSchemaStr.replace(/\"\$\$ref\"/g, '\"\$ref\"');
|
|
817
|
+
// 替换 x-apifox-overrides 为 APIPOST_OVERRIDES
|
|
818
|
+
jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-overrides\"/g, '\"x-schema-overrides\"');
|
|
819
|
+
// 还原为对象
|
|
820
|
+
jsonSchema = JSON.parse(jsonSchemaStr);
|
|
821
|
+
if (lodash.has(jsonSchema, 'ref') || lodash.has(jsonSchema, '$ref')) {
|
|
822
|
+
let newIuid = apipostTools.snowflakeId();
|
|
823
|
+
if ((jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.ref) && jsonSchema.ref.startsWith("http://localhost:8000/")) {
|
|
824
|
+
// jsonSchema.ref = jsonSchema.ref.substring(22);
|
|
825
|
+
const index = (_a = jsonSchema.ref) === null || _a === void 0 ? void 0 : _a.indexOf('#');
|
|
826
|
+
if (index !== -1) {
|
|
827
|
+
jsonSchema.ref = jsonSchema.ref.substring(index);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
jsonSchema = {
|
|
831
|
+
['x-schema-refs']: {
|
|
832
|
+
[newIuid]: {
|
|
833
|
+
$ref: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.ref) || (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema['$ref'])
|
|
834
|
+
},
|
|
835
|
+
},
|
|
836
|
+
properties: {},
|
|
837
|
+
['x-schema-orders']: [newIuid],
|
|
838
|
+
type: "object",
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
replaceRef(jsonSchema);
|
|
843
|
+
}
|
|
1159
844
|
}
|
|
1160
|
-
|
|
845
|
+
catch (error) { }
|
|
846
|
+
return jsonSchema;
|
|
1161
847
|
};
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
848
|
+
const escapeRegExp = (str) => {
|
|
849
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
850
|
+
};
|
|
851
|
+
const createNewModelData2 = (item, model_name) => {
|
|
852
|
+
var model = {
|
|
853
|
+
model_id: `#/definitions/${model_name}`,
|
|
854
|
+
name: model_name || 'New Schema',
|
|
855
|
+
displayName: model_name || '',
|
|
856
|
+
display_name: model_name || '',
|
|
857
|
+
model_type: 'model',
|
|
858
|
+
description: (item === null || item === void 0 ? void 0 : item.description) || '',
|
|
859
|
+
schema: {},
|
|
1171
860
|
};
|
|
1172
|
-
|
|
1173
|
-
|
|
861
|
+
try {
|
|
862
|
+
model.schema = swaggerSchema2apipostSchema(item);
|
|
1174
863
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
864
|
+
catch (error) { }
|
|
865
|
+
return model;
|
|
866
|
+
};
|
|
867
|
+
const createDataModelNewFolder = (folder_name) => {
|
|
868
|
+
var newFolder = {
|
|
869
|
+
'model_id': '',
|
|
870
|
+
'name': folder_name || 'New Folder',
|
|
871
|
+
'model_type': 'folder',
|
|
872
|
+
'description': folder_name || '',
|
|
873
|
+
'children': [],
|
|
874
|
+
};
|
|
875
|
+
return newFolder;
|
|
876
|
+
};
|
|
877
|
+
const createNewModelData = (item, key, folder_name) => {
|
|
878
|
+
var model = {
|
|
879
|
+
model_id: `#/components/${folder_name}/${key}`,
|
|
880
|
+
name: key || (item === null || item === void 0 ? void 0 : item.title) || key || 'New Schema',
|
|
881
|
+
// displayName:key || item?.title || '',
|
|
882
|
+
// display_name:key || item?.title || '',
|
|
883
|
+
model_type: 'model',
|
|
884
|
+
description: (item === null || item === void 0 ? void 0 : item.description) || '',
|
|
885
|
+
schema: {},
|
|
886
|
+
};
|
|
887
|
+
try {
|
|
888
|
+
model.schema = swaggerSchema2apipostSchema(item);
|
|
1177
889
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
890
|
+
catch (error) { }
|
|
891
|
+
return model;
|
|
892
|
+
};
|
|
893
|
+
const endsWith = (str, suffix) => {
|
|
894
|
+
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
895
|
+
};
|
|
896
|
+
const transFieldType = (str) => {
|
|
897
|
+
var _a;
|
|
898
|
+
if (!str)
|
|
899
|
+
return 'String';
|
|
900
|
+
return ((_a = str === null || str === void 0 ? void 0 : str.charAt(0)) === null || _a === void 0 ? void 0 : _a.toUpperCase()) + (str === null || str === void 0 ? void 0 : str.slice(1));
|
|
901
|
+
};
|
|
902
|
+
const getFidldType = (type) => {
|
|
903
|
+
if (!type)
|
|
904
|
+
return 'String';
|
|
905
|
+
if (DEFAULT_FIELD_TYPE$2.includes(type === null || type === void 0 ? void 0 : type.toLowerCase())) {
|
|
906
|
+
return transFieldType(type);
|
|
1180
907
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
908
|
+
return 'String';
|
|
909
|
+
};
|
|
910
|
+
const getExampleId = (status) => {
|
|
911
|
+
if (status == 200) {
|
|
912
|
+
return '1';
|
|
1183
913
|
}
|
|
1184
|
-
if (
|
|
1185
|
-
|
|
914
|
+
else if (status == 404) {
|
|
915
|
+
return '2';
|
|
1186
916
|
}
|
|
1187
|
-
|
|
1188
|
-
|
|
917
|
+
else {
|
|
918
|
+
return apipostTools.snowflakeId();
|
|
1189
919
|
}
|
|
1190
|
-
if (['http', 'sse'].includes(target_type)) {
|
|
1191
|
-
// 处理 Query 和 Header 参数
|
|
1192
|
-
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);
|
|
1193
|
-
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);
|
|
1194
|
-
handlePathItemParameters("cookie", ((_g = (_f = item === null || item === void 0 ? void 0 : item.request) === null || _f === void 0 ? void 0 : _f.cookie) === null || _g === void 0 ? void 0 : _g.parameter) || [], pathItem);
|
|
1195
|
-
handlePathItemParameters("path", ((_j = (_h = item === null || item === void 0 ? void 0 : item.request) === null || _h === void 0 ? void 0 : _h.restful) === null || _j === void 0 ? void 0 : _j.parameter) || [], pathItem);
|
|
1196
|
-
// 处理请求体参数(根据 Swagger 版本)
|
|
1197
|
-
if (apiVersion === "2.0") {
|
|
1198
|
-
handlePathItemBodyParameters(((_k = item === null || item === void 0 ? void 0 : item.request) === null || _k === void 0 ? void 0 : _k.body) || {}, pathItem, modelsObj);
|
|
1199
|
-
}
|
|
1200
|
-
else {
|
|
1201
|
-
handlePathItemRequestBody(((_l = item === null || item === void 0 ? void 0 : item.request) === null || _l === void 0 ? void 0 : _l.body) || {}, pathItem, modelsObj);
|
|
1202
|
-
}
|
|
1203
|
-
// 添加路径标签
|
|
1204
|
-
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
1205
|
-
pathItem.tags = [...pathItem.tags, path];
|
|
1206
|
-
}
|
|
1207
|
-
// 处理响应
|
|
1208
|
-
pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
|
|
1209
|
-
}
|
|
1210
|
-
else if (['websocket2', 'socketio', 'graphql'].includes(target_type)) {
|
|
1211
|
-
// 拼接description
|
|
1212
|
-
if (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.config)) {
|
|
1213
|
-
switch (target_type) {
|
|
1214
|
-
case 'socketio':
|
|
1215
|
-
pathItem.description = `${pathItem.description}
|
|
1216
|
-
${((_m = item === null || item === void 0 ? void 0 : item.config) === null || _m === void 0 ? void 0 : _m.shake_hands_path) ? t('securityConnectionMessage', {
|
|
1217
|
-
enable: ((_o = item === null || item === void 0 ? void 0 : item.config) === null || _o === void 0 ? void 0 : _o.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
|
|
1218
|
-
version: ((_p = item === null || item === void 0 ? void 0 : item.config) === null || _p === void 0 ? void 0 : _p.socket_version) || 'v4',
|
|
1219
|
-
path: (_q = item === null || item === void 0 ? void 0 : item.config) === null || _q === void 0 ? void 0 : _q.shake_hands_path
|
|
1220
|
-
}) : t('securityConnectionMessageNoPath', {
|
|
1221
|
-
enable: ((_r = item === null || item === void 0 ? void 0 : item.config) === null || _r === void 0 ? void 0 : _r.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
|
|
1222
|
-
version: ((_s = item === null || item === void 0 ? void 0 : item.config) === null || _s === void 0 ? void 0 : _s.socket_version) || 'v4',
|
|
1223
|
-
})}
|
|
1224
|
-
`;
|
|
1225
|
-
break;
|
|
1226
|
-
case 'websocket2':
|
|
1227
|
-
pathItem.description = `${pathItem.description}
|
|
1228
|
-
${t('wsConfigMessage', {
|
|
1229
|
-
enable: ((_t = item === null || item === void 0 ? void 0 : item.config) === null || _t === void 0 ? void 0 : _t.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
|
|
1230
|
-
content: !((_u = item === null || item === void 0 ? void 0 : item.config) === null || _u === void 0 ? void 0 : _u.information_size) || ((_v = item === null || item === void 0 ? void 0 : item.config) === null || _v === void 0 ? void 0 : _v.information_size) == 0 ? t('unlimited') : `${(_w = item === null || item === void 0 ? void 0 : item.config) === null || _w === void 0 ? void 0 : _w.information_size}M`
|
|
1231
|
-
})}
|
|
1232
|
-
`;
|
|
1233
|
-
break;
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
handlePathItemParameters("query", ((_y = (_x = item === null || item === void 0 ? void 0 : item.request) === null || _x === void 0 ? void 0 : _x.query) === null || _y === void 0 ? void 0 : _y.parameter) || [], pathItem);
|
|
1237
|
-
handlePathItemParameters("header", ((_0 = (_z = item === null || item === void 0 ? void 0 : item.request) === null || _z === void 0 ? void 0 : _z.header) === null || _0 === void 0 ? void 0 : _0.parameter) || [], pathItem);
|
|
1238
|
-
handlePathItemParameters("cookie", ((_2 = (_1 = item === null || item === void 0 ? void 0 : item.request) === null || _1 === void 0 ? void 0 : _1.cookie) === null || _2 === void 0 ? void 0 : _2.parameter) || [], pathItem);
|
|
1239
|
-
handlePathItemParameters("path", ((_4 = (_3 = item === null || item === void 0 ? void 0 : item.request) === null || _3 === void 0 ? void 0 : _3.restful) === null || _4 === void 0 ? void 0 : _4.parameter) || [], pathItem);
|
|
1240
|
-
if (target_type == 'socketio')
|
|
1241
|
-
handlePathItemParameters("event", ((_6 = (_5 = item === null || item === void 0 ? void 0 : item.request) === null || _5 === void 0 ? void 0 : _5.event) === null || _6 === void 0 ? void 0 : _6.parameter) || [], pathItem);
|
|
1242
|
-
// 处理请体
|
|
1243
|
-
if (target_type == 'graphql') {
|
|
1244
|
-
handleGraphqlRequestBody(((_8 = (_7 = item === null || item === void 0 ? void 0 : item.request) === null || _7 === void 0 ? void 0 : _7.body) === null || _8 === void 0 ? void 0 : _8.query_list) || [], ((_10 = (_9 = item === null || item === void 0 ? void 0 : item.request) === null || _9 === void 0 ? void 0 : _9.body) === null || _10 === void 0 ? void 0 : _10.query_schema) || {}, pathItem, modelsObj);
|
|
1245
|
-
}
|
|
1246
|
-
else {
|
|
1247
|
-
handleMessagePathItemrequestBody((item === null || item === void 0 ? void 0 : item.message) || [], pathItem, modelsObj);
|
|
1248
|
-
}
|
|
1249
|
-
// 添加路径标签
|
|
1250
|
-
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
1251
|
-
pathItem.tags = [...pathItem.tags, path];
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
else if (target_type == 'socket_method') {
|
|
1255
|
-
// 拼接description
|
|
1256
|
-
const configs = (_11 = item === null || item === void 0 ? void 0 : item.request) === null || _11 === void 0 ? void 0 : _11.configs;
|
|
1257
|
-
if (lodash.isPlainObject(configs)) {
|
|
1258
|
-
let requestString = `${t('requestEncodingFormat', { format: configs === null || configs === void 0 ? void 0 : configs.charset })} ${lodash.isArray((_12 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _12 === void 0 ? void 0 : _12.request) && ((_13 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _13 === void 0 ? void 0 : _13.request.length) > 0 ?
|
|
1259
|
-
`\n${t('needAddRequestDataHandleFunction')}\n${(_14 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _14 === void 0 ? void 0 : _14.request.map((r, index) => {
|
|
1260
|
-
let str = getTcpMethodFucString(r);
|
|
1261
|
-
return str;
|
|
1262
|
-
})}`
|
|
1263
|
-
: ''}`;
|
|
1264
|
-
let responseString = lodash.isArray((_15 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _15 === void 0 ? void 0 : _15.response) && ((_16 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _16 === void 0 ? void 0 : _16.response.length) > 0 ?
|
|
1265
|
-
`${t('needAddResponseDataHandleFunction')}\n${(_17 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _17 === void 0 ? void 0 : _17.response.map((r, index) => {
|
|
1266
|
-
let str = getTcpMethodFucString(r);
|
|
1267
|
-
return str;
|
|
1268
|
-
})}`
|
|
1269
|
-
: '';
|
|
1270
|
-
pathItem.description = `${pathItem.description}\n${requestString}\n${responseString}`;
|
|
1271
|
-
}
|
|
1272
|
-
handleSocketMethodRequestBody(((_18 = item === null || item === void 0 ? void 0 : item.request) === null || _18 === void 0 ? void 0 : _18.body) || {}, pathItem);
|
|
1273
|
-
// 处理响应
|
|
1274
|
-
pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
|
|
1275
|
-
// 添加路径标签
|
|
1276
|
-
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
1277
|
-
pathItem.tags = [...pathItem.tags, path];
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
else if (target_type == 'doc') {
|
|
1281
|
-
// 添加路径标签
|
|
1282
|
-
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
1283
|
-
pathItem.tags = [...pathItem.tags, path];
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
return pathItem;
|
|
1287
|
-
};
|
|
1288
|
-
const getTcpMethodFucString = (func) => {
|
|
1289
|
-
switch (func === null || func === void 0 ? void 0 : func.id) {
|
|
1290
|
-
case 'addCharToPacketEnd':
|
|
1291
|
-
return t('addNewline', { str: func === null || func === void 0 ? void 0 : func.option });
|
|
1292
|
-
case 'calcLengthToPacketHeader':
|
|
1293
|
-
return t('addContentLength', { size: func === null || func === void 0 ? void 0 : func.option });
|
|
1294
|
-
case 'removePacketHeader':
|
|
1295
|
-
return t('removeResponseHeader', { size: func === null || func === void 0 ? void 0 : func.option });
|
|
1296
|
-
case 'removeWrapChar':
|
|
1297
|
-
return t('trimTrailingNewline', { str: func === null || func === void 0 ? void 0 : func.option });
|
|
1298
|
-
case 'parseXmlToJson':
|
|
1299
|
-
return t('convertXmlToJson');
|
|
1300
|
-
}
|
|
1301
|
-
return '';
|
|
1302
920
|
};
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
921
|
+
const completionParameter = (parameter) => {
|
|
922
|
+
if (lodash.isArray(parameter)) {
|
|
923
|
+
return parameter.map((p) => {
|
|
924
|
+
var _a, _b;
|
|
925
|
+
return {
|
|
926
|
+
is_checked: 1, // 是否选择
|
|
927
|
+
key: (p === null || p === void 0 ? void 0 : p.name) || "", //参数名
|
|
928
|
+
value: transExample(p === null || p === void 0 ? void 0 : p.example) ||
|
|
929
|
+
transExample((_a = p === null || p === void 0 ? void 0 : p.schema) === null || _a === void 0 ? void 0 : _a.example) ||
|
|
930
|
+
transExample(p === null || p === void 0 ? void 0 : p.default) ||
|
|
931
|
+
"", //参数值
|
|
932
|
+
not_null: p.required ? 1 : -1, // 是否为空
|
|
933
|
+
description: anyToString(p === null || p === void 0 ? void 0 : p.description) || "", // 参数描述
|
|
934
|
+
field_type: getFidldType((_b = p === null || p === void 0 ? void 0 : p.schema) === null || _b === void 0 ? void 0 : _b.type), // 类型
|
|
935
|
+
param_id: apipostTools.snowflakeId(),
|
|
936
|
+
schema: (p === null || p === void 0 ? void 0 : p.schema) || {}
|
|
937
|
+
};
|
|
938
|
+
});
|
|
1315
939
|
}
|
|
1316
|
-
return
|
|
1317
|
-
};
|
|
1318
|
-
|
|
1319
|
-
const throwResult$1 = (status, message, data = '') => {
|
|
1320
|
-
return {
|
|
1321
|
-
status,
|
|
1322
|
-
message,
|
|
1323
|
-
data,
|
|
1324
|
-
};
|
|
940
|
+
return [];
|
|
1325
941
|
};
|
|
1326
|
-
const
|
|
1327
|
-
|
|
1328
|
-
return
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
942
|
+
const completionBodyParameter = (properties) => {
|
|
943
|
+
return lodash.map(properties, (value, key) => {
|
|
944
|
+
return {
|
|
945
|
+
is_checked: 1,
|
|
946
|
+
key: key || "",
|
|
947
|
+
value: transExample(value === null || value === void 0 ? void 0 : value.example) || "",
|
|
948
|
+
not_null: (value === null || value === void 0 ? void 0 : value.required) ? 1 : -1,
|
|
949
|
+
description: anyToString(value === null || value === void 0 ? void 0 : value.description) || "",
|
|
950
|
+
field_type: lodash.has(value, "type")
|
|
951
|
+
? value.type.charAt(0).toUpperCase() + value.type.slice(1)
|
|
952
|
+
: "String",
|
|
953
|
+
param_id: apipostTools.snowflakeId(),
|
|
954
|
+
schema: (value === null || value === void 0 ? void 0 : value.schema) || {}
|
|
955
|
+
};
|
|
956
|
+
});
|
|
1332
957
|
};
|
|
1333
|
-
const getBeautifulRaw
|
|
958
|
+
const getBeautifulRaw = (raw) => {
|
|
1334
959
|
var _a;
|
|
1335
960
|
try {
|
|
1336
961
|
if (!raw) {
|
|
@@ -1342,1389 +967,1781 @@ const getBeautifulRaw$1 = (raw) => {
|
|
|
1342
967
|
return raw;
|
|
1343
968
|
}
|
|
1344
969
|
};
|
|
1345
|
-
const
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
return false;
|
|
1354
|
-
}
|
|
1355
|
-
_url = lodash.trim(_url);
|
|
1356
|
-
return (_url.substr(0, 7).toLowerCase() === "http://" ||
|
|
1357
|
-
_url.substr(0, 8).toLowerCase() === "https://");
|
|
1358
|
-
};
|
|
1359
|
-
const createUrl = (_url) => {
|
|
1360
|
-
if (typeof _url !== "string") {
|
|
1361
|
-
_url += "";
|
|
1362
|
-
}
|
|
1363
|
-
if (!isURL(_url)) {
|
|
1364
|
-
_url = `http://${_url}`;
|
|
970
|
+
const completionBodyRaw = (bodyData) => {
|
|
971
|
+
let raw = '';
|
|
972
|
+
if (lodash.has(bodyData, "example")) {
|
|
973
|
+
let example = bodyData.example;
|
|
974
|
+
if (typeof example == "object") {
|
|
975
|
+
example = JSON.stringify(example);
|
|
976
|
+
}
|
|
977
|
+
raw = example;
|
|
1365
978
|
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
979
|
+
if (lodash.has(bodyData, "schema")) {
|
|
980
|
+
const raw_parameter = [];
|
|
981
|
+
const Raw = handleBodyJsonSchema(bodyData.schema, raw_parameter);
|
|
982
|
+
const Raw_text = lodash.isPlainObject(Raw) || Array.isArray(Raw)
|
|
983
|
+
? JSON.stringify(Raw)
|
|
984
|
+
: Raw;
|
|
985
|
+
raw = raw ? raw : Raw_text;
|
|
986
|
+
// if (isEmpty(raw)) {
|
|
987
|
+
// try {
|
|
988
|
+
// const myMockSchema = new (MockSchema as any)();
|
|
989
|
+
// const schemaJson = await myMockSchema.mock(bodyData.schema);
|
|
990
|
+
// raw =
|
|
991
|
+
// isPlainObject(schemaJson) || Array.isArray(Raw)
|
|
992
|
+
// ? JSON.stringify(schemaJson)
|
|
993
|
+
// : schemaJson;
|
|
994
|
+
// } catch (error) { }
|
|
995
|
+
// }
|
|
1378
996
|
}
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
const a = document.createElement("a");
|
|
1382
|
-
a.href = http_url;
|
|
1383
|
-
urls = {
|
|
1384
|
-
source: _url,
|
|
1385
|
-
href: a.href,
|
|
1386
|
-
protocol: a.protocol,
|
|
1387
|
-
host: a.hostname,
|
|
1388
|
-
hostname: a.hostname,
|
|
1389
|
-
port: a.port,
|
|
1390
|
-
origin: a.origin,
|
|
1391
|
-
search: a.search,
|
|
1392
|
-
pathname: a.pathname,
|
|
1393
|
-
// eslint-disable-next-line no-useless-escape
|
|
1394
|
-
file: (a.pathname.match(/\/([^\/?#]+)$/i) || ["", ""])[1],
|
|
1395
|
-
hash: a.hash,
|
|
1396
|
-
};
|
|
997
|
+
if (!lodash.isString(raw)) {
|
|
998
|
+
raw = JSON.stringify(raw);
|
|
1397
999
|
}
|
|
1398
|
-
return
|
|
1000
|
+
return getBeautifulRaw(raw);
|
|
1399
1001
|
};
|
|
1400
|
-
|
|
1401
|
-
const
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1002
|
+
const completionBodyRawParameter = (bodyData) => {
|
|
1003
|
+
const raw_parameter = [];
|
|
1004
|
+
handleBodyJsonSchema(bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema, raw_parameter);
|
|
1005
|
+
return raw_parameter;
|
|
1006
|
+
};
|
|
1007
|
+
const completionBody = (swaggerApi) => {
|
|
1008
|
+
var _a, _b;
|
|
1009
|
+
const content = ((_a = swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.requestBody) === null || _a === void 0 ? void 0 : _a.content) || {};
|
|
1010
|
+
const mode = lodash.isPlainObject(content) && !lodash.isEmpty(content) ? Object.keys(content)[0] : "none";
|
|
1011
|
+
const bodyData = (content === null || content === void 0 ? void 0 : content[mode]) || {};
|
|
1012
|
+
const apipostMode = getApipostMode(mode);
|
|
1013
|
+
let properties = {};
|
|
1014
|
+
if (lodash.has(bodyData, "schema")) {
|
|
1015
|
+
const { schema } = bodyData;
|
|
1016
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.type) === "array") {
|
|
1017
|
+
properties = (_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.properties;
|
|
1018
|
+
}
|
|
1019
|
+
else {
|
|
1020
|
+
properties = schema === null || schema === void 0 ? void 0 : schema.properties;
|
|
1021
|
+
}
|
|
1406
1022
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1023
|
+
return {
|
|
1024
|
+
mode: apipostMode || 'none',
|
|
1025
|
+
parameter: completionBodyParameter(properties),
|
|
1026
|
+
raw: completionBodyRaw(bodyData),
|
|
1027
|
+
raw_parameter: completionBodyRawParameter(bodyData),
|
|
1028
|
+
raw_schema: swaggerSchema2apipostSchema((bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema) || {}), // schema递归
|
|
1029
|
+
binary: null,
|
|
1030
|
+
};
|
|
1031
|
+
};
|
|
1032
|
+
const completionRequestParam = (swaggerApi) => {
|
|
1033
|
+
const parameters = lodash.isArray(swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.parameters) ? swaggerApi.parameters : [];
|
|
1034
|
+
return {
|
|
1035
|
+
header: {
|
|
1036
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'header' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1037
|
+
},
|
|
1038
|
+
query: {
|
|
1039
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'query' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1040
|
+
},
|
|
1041
|
+
restful: {
|
|
1042
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'path' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1043
|
+
},
|
|
1044
|
+
cookie: {
|
|
1045
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'cookie' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1046
|
+
},
|
|
1047
|
+
body: Object.assign({}, completionBody(swaggerApi)),
|
|
1048
|
+
};
|
|
1049
|
+
};
|
|
1050
|
+
const completionResponse = (responses) => {
|
|
1051
|
+
const example = [];
|
|
1052
|
+
if (lodash.isPlainObject(responses)) {
|
|
1053
|
+
Object.keys(responses).forEach((status) => {
|
|
1054
|
+
var _a, _b, _c, _d;
|
|
1055
|
+
const element = responses[status];
|
|
1056
|
+
if ((lodash.has(element, "schema") &&
|
|
1057
|
+
lodash.has(element.schema, "properties") &&
|
|
1058
|
+
JSON.stringify(element.schema.properties) !== "{}") ||
|
|
1059
|
+
((_a = element === null || element === void 0 ? void 0 : element.schema) === null || _a === void 0 ? void 0 : _a.type) === "array") {
|
|
1060
|
+
const raw_parameter = [];
|
|
1061
|
+
const Raw = handleBodyJsonSchema(element.schema, raw_parameter);
|
|
1062
|
+
const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
|
|
1063
|
+
? JSON.stringify(Raw)
|
|
1064
|
+
: String(Raw);
|
|
1065
|
+
const Raw_text = getBeautifulRaw(originRaw);
|
|
1066
|
+
let jsonSchema = {};
|
|
1067
|
+
if (Object.prototype.toString.call((_b = element === null || element === void 0 ? void 0 : element.schema) === null || _b === void 0 ? void 0 : _b["$$ref"]) ===
|
|
1068
|
+
"[object String]") {
|
|
1069
|
+
jsonSchema = swaggerSchema2apipostSchema(element.schema);
|
|
1070
|
+
}
|
|
1071
|
+
else {
|
|
1072
|
+
jsonSchema = element.schema;
|
|
1073
|
+
}
|
|
1074
|
+
// 成功响应示例
|
|
1075
|
+
if (String(status) == '200') {
|
|
1076
|
+
example.push({
|
|
1077
|
+
example_id: "1",
|
|
1078
|
+
raw: Raw_text,
|
|
1079
|
+
raw_parameter: raw_parameter,
|
|
1080
|
+
expect: {
|
|
1081
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1082
|
+
code: getSubstring(status, 128),
|
|
1083
|
+
content_type: "json",
|
|
1084
|
+
is_default: 1,
|
|
1085
|
+
mock: "",
|
|
1086
|
+
schema: jsonSchema,
|
|
1087
|
+
verify_type: "schema",
|
|
1088
|
+
},
|
|
1440
1089
|
});
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1090
|
+
}
|
|
1091
|
+
else if (String(status) == '404') {
|
|
1092
|
+
example.push({
|
|
1093
|
+
example_id: "2",
|
|
1094
|
+
raw: Raw_text,
|
|
1095
|
+
raw_parameter: raw_parameter,
|
|
1096
|
+
expect: {
|
|
1097
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1098
|
+
code: getSubstring(status, 128),
|
|
1099
|
+
content_type: "json",
|
|
1100
|
+
is_default: -1,
|
|
1101
|
+
mock: "",
|
|
1102
|
+
schema: jsonSchema,
|
|
1103
|
+
verify_type: "schema",
|
|
1104
|
+
},
|
|
1453
1105
|
});
|
|
1454
1106
|
}
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1107
|
+
else {
|
|
1108
|
+
// 其他示例
|
|
1109
|
+
const newUUID = apipostTools.snowflakeId();
|
|
1110
|
+
example.push({
|
|
1111
|
+
example_id: newUUID,
|
|
1112
|
+
raw: Raw_text,
|
|
1113
|
+
raw_parameter: raw_parameter,
|
|
1114
|
+
expect: {
|
|
1115
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1116
|
+
code: getSubstring(status, 128),
|
|
1117
|
+
content_type: "json",
|
|
1118
|
+
is_default: -1,
|
|
1119
|
+
mock: "",
|
|
1120
|
+
schema: jsonSchema,
|
|
1121
|
+
verify_type: "schema",
|
|
1122
|
+
},
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
else if (lodash.has(element, "content") &&
|
|
1127
|
+
((_c = Object.keys(element.content)) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
1128
|
+
const content = element.content;
|
|
1129
|
+
const mode = content instanceof Object ? Object.keys(content)[0] : "none";
|
|
1130
|
+
const bodyData = (content === null || content === void 0 ? void 0 : content[mode]) || {};
|
|
1131
|
+
const apipostMode = getApipostMode(mode);
|
|
1132
|
+
// let properties: any = {};
|
|
1133
|
+
if (lodash.has(bodyData, "schema")) {
|
|
1134
|
+
const { schema } = bodyData;
|
|
1135
|
+
if (lodash.has(schema, "properties")) ;
|
|
1136
|
+
if (lodash.has(schema, "items")) ;
|
|
1137
|
+
}
|
|
1138
|
+
if (apipostMode == "json") {
|
|
1139
|
+
let jsonSchema = {};
|
|
1140
|
+
if (Object.prototype.toString.call((_d = bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema) === null || _d === void 0 ? void 0 : _d["$$ref"]) === "[object String]") {
|
|
1141
|
+
jsonSchema = swaggerSchema2apipostSchema(bodyData.schema);
|
|
1142
|
+
}
|
|
1143
|
+
else if (lodash.isPlainObject(bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema)) {
|
|
1144
|
+
jsonSchema = bodyData.schema;
|
|
1145
|
+
}
|
|
1146
|
+
if (lodash.has(bodyData, "example")) {
|
|
1147
|
+
const example = bodyData.example;
|
|
1148
|
+
if (status == 200 || status == 404) {
|
|
1149
|
+
let originRaw;
|
|
1150
|
+
try {
|
|
1151
|
+
if (Object.prototype.toString.call(example) ===
|
|
1152
|
+
"[object Object]") {
|
|
1153
|
+
originRaw = JSON.stringify(Object.assign({}, example));
|
|
1154
|
+
}
|
|
1155
|
+
else {
|
|
1156
|
+
originRaw = String(example);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
catch (error) {
|
|
1160
|
+
originRaw = String(example);
|
|
1161
|
+
}
|
|
1162
|
+
const Raw_text = getBeautifulRaw(originRaw);
|
|
1163
|
+
example.push({
|
|
1164
|
+
example_id: status == 200 ? "1" : "2",
|
|
1165
|
+
raw: Raw_text,
|
|
1166
|
+
raw_parameter: [],
|
|
1167
|
+
expect: {
|
|
1168
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1169
|
+
code: getSubstring(status, 128),
|
|
1170
|
+
content_type: "json",
|
|
1171
|
+
is_default: status == 200 ? 1 : -1,
|
|
1172
|
+
mock: "",
|
|
1173
|
+
schema: jsonSchema,
|
|
1174
|
+
verify_type: "schema",
|
|
1175
|
+
},
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
else {
|
|
1179
|
+
// 其他示例
|
|
1180
|
+
const newUUID = apipostTools.snowflakeId();
|
|
1181
|
+
let originRaw;
|
|
1182
|
+
try {
|
|
1183
|
+
if (Object.prototype.toString.call(example) ===
|
|
1184
|
+
"[object Object]") {
|
|
1185
|
+
originRaw = JSON.stringify(Object.assign({}, example));
|
|
1186
|
+
}
|
|
1187
|
+
else {
|
|
1188
|
+
originRaw = example;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
catch (error) {
|
|
1192
|
+
originRaw = String(example);
|
|
1193
|
+
}
|
|
1194
|
+
const Raw_text = getBeautifulRaw(originRaw);
|
|
1195
|
+
example.push({
|
|
1196
|
+
example_id: newUUID,
|
|
1197
|
+
raw: Raw_text,
|
|
1198
|
+
raw_parameter: [],
|
|
1199
|
+
expect: {
|
|
1200
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1201
|
+
code: getSubstring(status, 128),
|
|
1202
|
+
content_type: "json",
|
|
1203
|
+
is_default: -1,
|
|
1204
|
+
mock: "",
|
|
1205
|
+
schema: jsonSchema,
|
|
1206
|
+
verify_type: "schema",
|
|
1207
|
+
},
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
else {
|
|
1212
|
+
if (lodash.isPlainObject(bodyData) && lodash.has(bodyData, "schema")) {
|
|
1213
|
+
const raw_parameter = [];
|
|
1214
|
+
const Raw = handleBodyJsonSchema((bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema) || {}, raw_parameter);
|
|
1215
|
+
const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
|
|
1216
|
+
? JSON.stringify(Raw)
|
|
1217
|
+
: String(Raw);
|
|
1218
|
+
const Raw_text = getBeautifulRaw(originRaw);
|
|
1219
|
+
if (status == 200 || status == 404) {
|
|
1220
|
+
example.push({
|
|
1221
|
+
example_id: status == 200 ? "1" : "2",
|
|
1222
|
+
raw: Raw_text,
|
|
1223
|
+
raw_parameter: raw_parameter,
|
|
1224
|
+
expect: {
|
|
1225
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1226
|
+
code: getSubstring(status, 128),
|
|
1227
|
+
content_type: "json",
|
|
1228
|
+
is_default: status == 200 ? 1 : -1,
|
|
1229
|
+
mock: "",
|
|
1230
|
+
schema: jsonSchema,
|
|
1231
|
+
verify_type: "schema",
|
|
1232
|
+
},
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
else {
|
|
1236
|
+
// 其他示例
|
|
1237
|
+
const newUUID = apipostTools.snowflakeId();
|
|
1238
|
+
example.push({
|
|
1239
|
+
example_id: newUUID,
|
|
1240
|
+
raw: Raw_text,
|
|
1241
|
+
raw_parameter: raw_parameter,
|
|
1242
|
+
expect: {
|
|
1243
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1244
|
+
code: getSubstring(status, 128),
|
|
1245
|
+
content_type: "json",
|
|
1246
|
+
is_default: -1,
|
|
1247
|
+
mock: "",
|
|
1248
|
+
schema: jsonSchema,
|
|
1249
|
+
verify_type: "schema",
|
|
1250
|
+
},
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
else {
|
|
1258
|
+
example.push({
|
|
1259
|
+
example_id: getExampleId(status),
|
|
1260
|
+
raw: "",
|
|
1261
|
+
raw_parameter: [],
|
|
1262
|
+
expect: {
|
|
1263
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status || "", 255),
|
|
1264
|
+
code: getSubstring(status, 128),
|
|
1265
|
+
content_type: "json",
|
|
1266
|
+
is_default: -1,
|
|
1267
|
+
mock: "",
|
|
1268
|
+
schema: { type: "object", properties: {} },
|
|
1269
|
+
verify_type: "schema",
|
|
1270
|
+
},
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
return {
|
|
1276
|
+
is_check_result: 1,
|
|
1277
|
+
example,
|
|
1278
|
+
};
|
|
1279
|
+
};
|
|
1280
|
+
const completionWs2Config = () => {
|
|
1281
|
+
// if (isPlainObject(config)) {
|
|
1282
|
+
// return {
|
|
1283
|
+
// information_size: config?.information_size || 5,
|
|
1284
|
+
// certificate_verification: config?.certificate_verification || -1,
|
|
1285
|
+
// reconnect_num: config?.reconnect_num || 5,
|
|
1286
|
+
// reconnect_time: config?.reconnect_time || 5000,
|
|
1287
|
+
// shake_hands_timeout: config?.shake_hands_timeout || 0,
|
|
1288
|
+
// };
|
|
1289
|
+
// }
|
|
1290
|
+
return {
|
|
1291
|
+
certificate_verification: -1,
|
|
1292
|
+
information_size: 5,
|
|
1293
|
+
reconnect_num: 5,
|
|
1294
|
+
reconnect_time: 5000,
|
|
1295
|
+
shake_hands_timeout: 0,
|
|
1296
|
+
};
|
|
1297
|
+
};
|
|
1298
|
+
const completionSocketIoConfig = () => {
|
|
1299
|
+
// if (isPlainObject(config)) {
|
|
1300
|
+
// return {
|
|
1301
|
+
// reconnect_num: config?.reconnect_num || 5,
|
|
1302
|
+
// reconnect_time: config?.reconnect_time || 5000,
|
|
1303
|
+
// shake_hands_path: config?.shake_hands_path || '/socket.io',
|
|
1304
|
+
// shake_hands_timeout: config?.shake_hands_timeout || 0,
|
|
1305
|
+
// socket_version: config?.socket_version || 'v4',
|
|
1306
|
+
// certificate_verification: config?.certificate_verification || -1,
|
|
1307
|
+
// };
|
|
1308
|
+
// }
|
|
1309
|
+
return {
|
|
1310
|
+
reconnect_num: 5,
|
|
1311
|
+
reconnect_time: 5000,
|
|
1312
|
+
shake_hands_path: '/socket.io',
|
|
1313
|
+
shake_hands_timeout: 0,
|
|
1314
|
+
socket_version: 'v4',
|
|
1315
|
+
certificate_verification: -1,
|
|
1316
|
+
};
|
|
1317
|
+
};
|
|
1318
|
+
const completionWs2Request = (swaggerApi) => {
|
|
1319
|
+
const parameters = lodash.isArray(swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.parameters) ? swaggerApi.parameters : [];
|
|
1320
|
+
return {
|
|
1321
|
+
header: {
|
|
1322
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'header' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1323
|
+
},
|
|
1324
|
+
query: {
|
|
1325
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'query' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1326
|
+
},
|
|
1327
|
+
cookie: {
|
|
1328
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'cookie' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1329
|
+
},
|
|
1330
|
+
};
|
|
1331
|
+
};
|
|
1332
|
+
const completionWs2Message = (swaggerApi) => {
|
|
1333
|
+
var _a;
|
|
1334
|
+
const content = ((_a = swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.requestBody) === null || _a === void 0 ? void 0 : _a.content) || {};
|
|
1335
|
+
const msg = lodash.values(content);
|
|
1336
|
+
return msg === null || msg === void 0 ? void 0 : msg.map((item) => {
|
|
1337
|
+
const response = (item === null || item === void 0 ? void 0 : item['x-response']) || {};
|
|
1338
|
+
return {
|
|
1339
|
+
name: (item === null || item === void 0 ? void 0 : item['x-summary']) || 'Message',
|
|
1340
|
+
param_id: apipostTools.snowflakeId(),
|
|
1341
|
+
request: {
|
|
1342
|
+
mode: (item === null || item === void 0 ? void 0 : item['x-mode']) || 'text',
|
|
1343
|
+
raw: (item === null || item === void 0 ? void 0 : item.example) || '',
|
|
1344
|
+
raw_parameter: [],
|
|
1345
|
+
raw_schema: (item === null || item === void 0 ? void 0 : item.schema) || {},
|
|
1346
|
+
},
|
|
1347
|
+
response: {
|
|
1348
|
+
mode: (response === null || response === void 0 ? void 0 : response['x-mode']) || 'text',
|
|
1349
|
+
raw: (response === null || response === void 0 ? void 0 : response.example) || '',
|
|
1350
|
+
raw_parameter: [],
|
|
1351
|
+
raw_schema: (response === null || response === void 0 ? void 0 : response.schema) || {},
|
|
1352
|
+
},
|
|
1353
|
+
};
|
|
1354
|
+
});
|
|
1355
|
+
};
|
|
1356
|
+
const completionSocketIoRequest = (swaggerApi) => {
|
|
1357
|
+
var _a;
|
|
1358
|
+
const parameters = lodash.isArray(swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.parameters) ? swaggerApi.parameters : [];
|
|
1359
|
+
return {
|
|
1360
|
+
header: {
|
|
1361
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'header' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1362
|
+
},
|
|
1363
|
+
query: {
|
|
1364
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'query' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1365
|
+
},
|
|
1366
|
+
cookie: {
|
|
1367
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'cookie' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1368
|
+
},
|
|
1369
|
+
event: {
|
|
1370
|
+
parameter: lodash.isArray(parameters)
|
|
1371
|
+
? (_a = parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'event' && (p === null || p === void 0 ? void 0 : p.name))) === null || _a === void 0 ? void 0 : _a.map(({ description = '', schema = {}, is_checked = 1, name = '', example, required = true, }) => ({
|
|
1372
|
+
param_id: apipostTools.snowflakeId(),
|
|
1373
|
+
description,
|
|
1374
|
+
field_type: (schema === null || schema === void 0 ? void 0 : schema.type) || 'string',
|
|
1375
|
+
is_checked,
|
|
1376
|
+
key: name,
|
|
1377
|
+
value: lodash.isEqual(example, '1') ? example : '-1',
|
|
1378
|
+
not_null: required ? 1 : -1,
|
|
1379
|
+
}))
|
|
1380
|
+
: [],
|
|
1381
|
+
},
|
|
1382
|
+
};
|
|
1383
|
+
};
|
|
1384
|
+
const completionGraphqlRequestBody = (swaggerApi) => {
|
|
1385
|
+
var _a, _b;
|
|
1386
|
+
const content = ((_a = swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.requestBody) === null || _a === void 0 ? void 0 : _a.content) || {};
|
|
1387
|
+
const query_schema = ((_b = swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.requestBody) === null || _b === void 0 ? void 0 : _b['x-schema']) || {};
|
|
1388
|
+
return {
|
|
1389
|
+
query_list: lodash.values(content).map(item => {
|
|
1390
|
+
const response = (item === null || item === void 0 ? void 0 : item['x-response']) || {};
|
|
1391
|
+
return {
|
|
1392
|
+
param_id: apipostTools.snowflakeId(),
|
|
1393
|
+
name: item === null || item === void 0 ? void 0 : item['x-summary'],
|
|
1394
|
+
query: item === null || item === void 0 ? void 0 : item['x-query'],
|
|
1395
|
+
variables: item === null || item === void 0 ? void 0 : item['x-variables'],
|
|
1396
|
+
response: {
|
|
1397
|
+
mode: (response === null || response === void 0 ? void 0 : response['x-mode']) || 'json',
|
|
1398
|
+
raw: (response === null || response === void 0 ? void 0 : response.example) || '',
|
|
1399
|
+
raw_parameter: [],
|
|
1400
|
+
raw_schema: (response === null || response === void 0 ? void 0 : response.schema) || {},
|
|
1401
|
+
},
|
|
1402
|
+
};
|
|
1403
|
+
}),
|
|
1404
|
+
query_schema: lodash.isPlainObject(query_schema) ? query_schema : {},
|
|
1405
|
+
};
|
|
1406
|
+
};
|
|
1407
|
+
const completionGraphqlRequest = (swaggerApi) => {
|
|
1408
|
+
const parameters = lodash.isArray(swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.parameters) ? swaggerApi.parameters : [];
|
|
1409
|
+
return {
|
|
1410
|
+
header: {
|
|
1411
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'header' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1412
|
+
},
|
|
1413
|
+
cookie: {
|
|
1414
|
+
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'cookie' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
1415
|
+
},
|
|
1416
|
+
pre_tasks: [],
|
|
1417
|
+
post_tasks: [],
|
|
1418
|
+
body: completionGraphqlRequestBody(swaggerApi),
|
|
1419
|
+
};
|
|
1420
|
+
};
|
|
1421
|
+
const completionSocketMethodBody = (swaggerApi) => {
|
|
1422
|
+
var _a;
|
|
1423
|
+
const content = ((_a = swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.requestBody) === null || _a === void 0 ? void 0 : _a.content) || {};
|
|
1424
|
+
const mode = lodash.isPlainObject(content) && !lodash.isEmpty(content) ? Object.keys(content)[0] : "none";
|
|
1425
|
+
const bodyData = (content === null || content === void 0 ? void 0 : content[mode]) || {};
|
|
1426
|
+
const apipostMode = (MODE_TYPE2 === null || MODE_TYPE2 === void 0 ? void 0 : MODE_TYPE2[mode]) || 'xml';
|
|
1427
|
+
return {
|
|
1428
|
+
mode: apipostMode,
|
|
1429
|
+
parameter: [],
|
|
1430
|
+
raw: (bodyData === null || bodyData === void 0 ? void 0 : bodyData.example) || '',
|
|
1431
|
+
raw_parameter: [],
|
|
1432
|
+
raw_schema: (bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema) || {},
|
|
1433
|
+
};
|
|
1434
|
+
};
|
|
1435
|
+
const completionSocketMethodRequest = (swaggerApi) => {
|
|
1436
|
+
return {
|
|
1437
|
+
body: completionSocketMethodBody(swaggerApi),
|
|
1438
|
+
post_tasks: [],
|
|
1439
|
+
configs: {
|
|
1440
|
+
charset: 'utf8',
|
|
1441
|
+
func: {
|
|
1442
|
+
request: [],
|
|
1443
|
+
response: [],
|
|
1444
|
+
},
|
|
1445
|
+
},
|
|
1446
|
+
};
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
var securityConnectionMessageNoPath$4 = "When connecting via a secure connection, {{enable}} server certificate validation, and use client version {{version}} with no specified handshake path.";
|
|
1450
|
+
var notNeedEnable$4 = "do not enable";
|
|
1451
|
+
var needEnable$4 = "please enable";
|
|
1452
|
+
var securityConnectionMessage$4 = "When connecting via a secure connection, {{enable}} server certificate validation, and use client version {{version}} with the specified handshake path {{path}}.";
|
|
1453
|
+
var wsConfigMessage$4 = "When connecting via a secure connection, {{enable}} server certificate validation, and the maximum allowed message size for reception is {{content}}.";
|
|
1454
|
+
var unlimited$4 = "unlimited";
|
|
1455
|
+
var left$4 = "Left";
|
|
1456
|
+
var right$4 = "Right";
|
|
1457
|
+
var tcpMethodMessage$4 = "{{direction}} pad to a length of {{size}}, padding character: {{str}}";
|
|
1458
|
+
var tcpMethodDelimiterMessage$4 = "Append the separator character {{str}} at the end.";
|
|
1459
|
+
var requestEncodingFormat$4 = "The encoding format for the request message is {{format}}.";
|
|
1460
|
+
var needAddRequestDataHandleFunction$4 = "Request data processing function needs to be added:";
|
|
1461
|
+
var needAddResponseDataHandleFunction$4 = "Response data processing function needs to be added:";
|
|
1462
|
+
var addNewline$4 = "Add a newline character {{str}} at the end of each request message";
|
|
1463
|
+
var addContentLength$4 = "calculate the content length (excluding the packet header), and append it to the packet header (text format, packet header byte length is {{size}}).";
|
|
1464
|
+
var removeResponseHeader$4 = "The response message needs to remove the packet header (length of {{size}} bytes)";
|
|
1465
|
+
var trimTrailingNewline$4 = "strip the newline character {{str}} at the end of the line";
|
|
1466
|
+
var convertXmlToJson$4 = "and convert the XML content to JSON format.";
|
|
1467
|
+
var specialCharText$4 = "For text-type messages, the packet tail contains special character {{str}}";
|
|
1468
|
+
var specialCharBinary$4 = "For binary-type messages, the packet tail contains special character {{str}}";
|
|
1469
|
+
var headerBodyFormat$4 = "[Header+Body] formatted message (header contains the byte length of the body), with a header length of {{size}} bytes";
|
|
1470
|
+
var fixedLength$4 = "The message has a fixed length of {{size}} bytes";
|
|
1471
|
+
var byte$4 = "bytes";
|
|
1472
|
+
var completeOnReceive$4 = "Completion is assumed upon data reception (subpacket handling is not addressed)";
|
|
1473
|
+
var serverAddress$4 = "Server address";
|
|
1474
|
+
var pktCompletion$4 = "Method to determine message reception completio";
|
|
1475
|
+
var createDir$4 = "Create directory";
|
|
1476
|
+
var createProj$4 = "Create project";
|
|
1477
|
+
var createEnv$4 = "Create environment";
|
|
1478
|
+
var en = {
|
|
1479
|
+
securityConnectionMessageNoPath: securityConnectionMessageNoPath$4,
|
|
1480
|
+
notNeedEnable: notNeedEnable$4,
|
|
1481
|
+
needEnable: needEnable$4,
|
|
1482
|
+
securityConnectionMessage: securityConnectionMessage$4,
|
|
1483
|
+
wsConfigMessage: wsConfigMessage$4,
|
|
1484
|
+
unlimited: unlimited$4,
|
|
1485
|
+
left: left$4,
|
|
1486
|
+
right: right$4,
|
|
1487
|
+
tcpMethodMessage: tcpMethodMessage$4,
|
|
1488
|
+
tcpMethodDelimiterMessage: tcpMethodDelimiterMessage$4,
|
|
1489
|
+
requestEncodingFormat: requestEncodingFormat$4,
|
|
1490
|
+
needAddRequestDataHandleFunction: needAddRequestDataHandleFunction$4,
|
|
1491
|
+
needAddResponseDataHandleFunction: needAddResponseDataHandleFunction$4,
|
|
1492
|
+
addNewline: addNewline$4,
|
|
1493
|
+
addContentLength: addContentLength$4,
|
|
1494
|
+
removeResponseHeader: removeResponseHeader$4,
|
|
1495
|
+
trimTrailingNewline: trimTrailingNewline$4,
|
|
1496
|
+
convertXmlToJson: convertXmlToJson$4,
|
|
1497
|
+
specialCharText: specialCharText$4,
|
|
1498
|
+
specialCharBinary: specialCharBinary$4,
|
|
1499
|
+
headerBodyFormat: headerBodyFormat$4,
|
|
1500
|
+
fixedLength: fixedLength$4,
|
|
1501
|
+
byte: byte$4,
|
|
1502
|
+
completeOnReceive: completeOnReceive$4,
|
|
1503
|
+
serverAddress: serverAddress$4,
|
|
1504
|
+
pktCompletion: pktCompletion$4,
|
|
1505
|
+
createDir: createDir$4,
|
|
1506
|
+
createProj: createProj$4,
|
|
1507
|
+
createEnv: createEnv$4
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
var securityConnectionMessageNoPath$3 = "Saat terhubung melalui koneksi yang aman, harap {{enable}} verifikasi sertifikat server dan gunakan versi klien {{version}} tanpa jalur handshake yang ditentukan.";
|
|
1511
|
+
var notNeedEnable$3 = "tidak aktifkan";
|
|
1512
|
+
var needEnable$3 = "aktifkan";
|
|
1513
|
+
var securityConnectionMessage$3 = "Saat terhubung melalui koneksi yang aman, harap {{enable}} verifikasi sertifikat server, dan gunakan versi klien {{version}} dengan jalur handshake yang ditentukan {{path}}.";
|
|
1514
|
+
var wsConfigMessage$3 = "Saat terhubung melalui koneksi yang aman, harap {{enable}} verifikasi sertifikat server, dan ukuran maksimum konten yang diperbolehkan untuk diterima adalah {{content}}.";
|
|
1515
|
+
var unlimited$3 = "tidak terbatas";
|
|
1516
|
+
var left$3 = "Isi sisi kiri hingga";
|
|
1517
|
+
var right$3 = "Isi sisi kanan hingga";
|
|
1518
|
+
var tcpMethodMessage$3 = "{{direction}} {{size}} karakter, gunakan karakter pengisi '{{str}}'.";
|
|
1519
|
+
var tcpMethodDelimiterMessage$3 = "Tambahkan karakter pemisah {{str}} di akhir.";
|
|
1520
|
+
var requestEncodingFormat$3 = "Format pengkodean untuk pesan permintaan adalah {{format}}.";
|
|
1521
|
+
var needAddRequestDataHandleFunction$3 = "Perlu menambahkan fungsi pemrosesan data permintaan:";
|
|
1522
|
+
var needAddResponseDataHandleFunction$3 = "Perlu menambahkan fungsi pemrosesan data respons:";
|
|
1523
|
+
var addNewline$3 = "Tambahkan karakter baris baru {{str}} di akhir setiap pesan permintaan";
|
|
1524
|
+
var addContentLength$3 = "hitung panjang konten (tidak termasuk header paket), dan tambahkan ke header paket (format teks, panjang byte header paket adalah {{size}}).";
|
|
1525
|
+
var removeResponseHeader$3 = "Pesan respons perlu menghapus header paket (panjang {{size}} byte)";
|
|
1526
|
+
var trimTrailingNewline$3 = "menghapus karakter baris baru {{str}} di akhir baris";
|
|
1527
|
+
var convertXmlToJson$3 = "dan mengonversi konten dalam format XML menjadi format JSON.";
|
|
1528
|
+
var specialCharText$3 = "Untuk pesan tipe teks, ujung paket mengandung karakter khusus {{str}}";
|
|
1529
|
+
var specialCharBinary$3 = "Untuk pesan tipe biner, ujung paket mengandung karakter khusus {{str}}";
|
|
1530
|
+
var headerBodyFormat$3 = "Pesan berformat [Kepala+Isi] (Kepala menyimpan panjang byte Isi), dengan panjang Kepala {{size}} byte";
|
|
1531
|
+
var fixedLength$3 = "Pesan memiliki panjang tetap ({{size}} byte)";
|
|
1532
|
+
var byte$3 = "byte";
|
|
1533
|
+
var completeOnReceive$3 = "Anggap data diterima sebagai lengkap (tanpa menangani segmentasi paket)";
|
|
1534
|
+
var serverAddress$3 = "Alamat server";
|
|
1535
|
+
var pktCompletion$3 = "Tentukan metode penyelesaian penerimaan pesan";
|
|
1536
|
+
var createDir$3 = "Buat direktori";
|
|
1537
|
+
var createProj$3 = "Buat proyek";
|
|
1538
|
+
var createEnv$3 = "Buat lingkungan";
|
|
1539
|
+
var id = {
|
|
1540
|
+
securityConnectionMessageNoPath: securityConnectionMessageNoPath$3,
|
|
1541
|
+
notNeedEnable: notNeedEnable$3,
|
|
1542
|
+
needEnable: needEnable$3,
|
|
1543
|
+
securityConnectionMessage: securityConnectionMessage$3,
|
|
1544
|
+
wsConfigMessage: wsConfigMessage$3,
|
|
1545
|
+
unlimited: unlimited$3,
|
|
1546
|
+
left: left$3,
|
|
1547
|
+
right: right$3,
|
|
1548
|
+
tcpMethodMessage: tcpMethodMessage$3,
|
|
1549
|
+
tcpMethodDelimiterMessage: tcpMethodDelimiterMessage$3,
|
|
1550
|
+
requestEncodingFormat: requestEncodingFormat$3,
|
|
1551
|
+
needAddRequestDataHandleFunction: needAddRequestDataHandleFunction$3,
|
|
1552
|
+
needAddResponseDataHandleFunction: needAddResponseDataHandleFunction$3,
|
|
1553
|
+
addNewline: addNewline$3,
|
|
1554
|
+
addContentLength: addContentLength$3,
|
|
1555
|
+
removeResponseHeader: removeResponseHeader$3,
|
|
1556
|
+
trimTrailingNewline: trimTrailingNewline$3,
|
|
1557
|
+
convertXmlToJson: convertXmlToJson$3,
|
|
1558
|
+
specialCharText: specialCharText$3,
|
|
1559
|
+
specialCharBinary: specialCharBinary$3,
|
|
1560
|
+
headerBodyFormat: headerBodyFormat$3,
|
|
1561
|
+
fixedLength: fixedLength$3,
|
|
1562
|
+
byte: byte$3,
|
|
1563
|
+
completeOnReceive: completeOnReceive$3,
|
|
1564
|
+
serverAddress: serverAddress$3,
|
|
1565
|
+
pktCompletion: pktCompletion$3,
|
|
1566
|
+
createDir: createDir$3,
|
|
1567
|
+
createProj: createProj$3,
|
|
1568
|
+
createEnv: createEnv$3
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
var securityConnectionMessageNoPath$2 = "安全な接続を介して接続する際は、サーバー証明書の検証を{{enable}}、クライアントバージョン{{version}}を使用し、指定されたハンドシェイクパスはありません。";
|
|
1572
|
+
var notNeedEnable$2 = "無効にし";
|
|
1573
|
+
var needEnable$2 = "有効にし";
|
|
1574
|
+
var securityConnectionMessage$2 = "安全な接続を介して接続する際は、サーバー証明書の検証を{{enable}}、クライアントバージョン{{version}}と指定されたハンドシェイクパス {{path}} を使用してください。";
|
|
1575
|
+
var wsConfigMessage$2 = "安全な接続を介して接続する際は、サーバー証明書の検証を{{enable}}、受信可能な最大メッセージサイズは{{content}}です。";
|
|
1576
|
+
var unlimited$2 = "無制限";
|
|
1577
|
+
var left$2 = "左側";
|
|
1578
|
+
var right$2 = "右側";
|
|
1579
|
+
var tcpMethodMessage$2 = "{{direction}}を長さ{{size}}にパディングし、パディング文字:{{str}}";
|
|
1580
|
+
var tcpMethodDelimiterMessage$2 = "末尾に区切り文字{{str}}を追加します。";
|
|
1581
|
+
var requestEncodingFormat$2 = "リクエストメッセージのエンコーディング形式は{{format}}です。";
|
|
1582
|
+
var needAddRequestDataHandleFunction$2 = "リクエストデータ処理関数を追加する必要があります:";
|
|
1583
|
+
var needAddResponseDataHandleFunction$2 = "応答データ処理関数を追加する必要があります:";
|
|
1584
|
+
var addNewline$2 = "各リクエストメッセージの末尾に改行文字{{str}}を追加し";
|
|
1585
|
+
var addContentLength$2 = "内容の長さを計算(パケットヘッダーを除く)して、それをパケットヘッダーに追加します(テキスト形式、パケットヘッダーのバイト長は{{size}}です)。";
|
|
1586
|
+
var removeResponseHeader$2 = "応答メッセージは、パケットヘッダー(長さ{{size}}バイト)";
|
|
1587
|
+
var trimTrailingNewline$2 = "を削除し、行末の改行文字{{str}}を取り除き";
|
|
1588
|
+
var convertXmlToJson$2 = "XML形式の内容をJSON形式に変換する必要があります。";
|
|
1589
|
+
var specialCharText$2 = "テキストタイプのメッセージでは、パケットの末尾に特殊文字 {{str}} が含まれています";
|
|
1590
|
+
var specialCharBinary$2 = "バイナリタイプのメッセージでは、パケットの末尾に特殊文字 {{str}} が含まれています";
|
|
1591
|
+
var headerBodyFormat$2 = "[ヘッダー+ボディ]フォーマットのメッセージ(ヘッダーにはボディのバイト長が含まれ、ヘッダー長は{{size}}バイトです)";
|
|
1592
|
+
var fixedLength$2 = "メッセージは固定長({{size}}バイト)です";
|
|
1593
|
+
var byte$2 = "バイト";
|
|
1594
|
+
var completeOnReceive$2 = "データを受信した時点で完了とみなします(パケット分割は処理しません)";
|
|
1595
|
+
var serverAddress$2 = "サーバーアドレス";
|
|
1596
|
+
var pktCompletion$2 = "メッセージ受信完了方法を判断する";
|
|
1597
|
+
var createDir$2 = "ディレクトリを作成する";
|
|
1598
|
+
var createProj$2 = "プロジェクトを作成する";
|
|
1599
|
+
var createEnv$2 = "環境を作成する";
|
|
1600
|
+
var ja = {
|
|
1601
|
+
securityConnectionMessageNoPath: securityConnectionMessageNoPath$2,
|
|
1602
|
+
notNeedEnable: notNeedEnable$2,
|
|
1603
|
+
needEnable: needEnable$2,
|
|
1604
|
+
securityConnectionMessage: securityConnectionMessage$2,
|
|
1605
|
+
wsConfigMessage: wsConfigMessage$2,
|
|
1606
|
+
unlimited: unlimited$2,
|
|
1607
|
+
left: left$2,
|
|
1608
|
+
right: right$2,
|
|
1609
|
+
tcpMethodMessage: tcpMethodMessage$2,
|
|
1610
|
+
tcpMethodDelimiterMessage: tcpMethodDelimiterMessage$2,
|
|
1611
|
+
requestEncodingFormat: requestEncodingFormat$2,
|
|
1612
|
+
needAddRequestDataHandleFunction: needAddRequestDataHandleFunction$2,
|
|
1613
|
+
needAddResponseDataHandleFunction: needAddResponseDataHandleFunction$2,
|
|
1614
|
+
addNewline: addNewline$2,
|
|
1615
|
+
addContentLength: addContentLength$2,
|
|
1616
|
+
removeResponseHeader: removeResponseHeader$2,
|
|
1617
|
+
trimTrailingNewline: trimTrailingNewline$2,
|
|
1618
|
+
convertXmlToJson: convertXmlToJson$2,
|
|
1619
|
+
specialCharText: specialCharText$2,
|
|
1620
|
+
specialCharBinary: specialCharBinary$2,
|
|
1621
|
+
headerBodyFormat: headerBodyFormat$2,
|
|
1622
|
+
fixedLength: fixedLength$2,
|
|
1623
|
+
byte: byte$2,
|
|
1624
|
+
completeOnReceive: completeOnReceive$2,
|
|
1625
|
+
serverAddress: serverAddress$2,
|
|
1626
|
+
pktCompletion: pktCompletion$2,
|
|
1627
|
+
createDir: createDir$2,
|
|
1628
|
+
createProj: createProj$2,
|
|
1629
|
+
createEnv: createEnv$2
|
|
1630
|
+
};
|
|
1631
|
+
|
|
1632
|
+
var securityConnectionMessageNoPath$1 = "在通过安全连接时,{{enable}}服务器证书验证,并使用客户端版本 {{version}} , 无指定握手路径。";
|
|
1633
|
+
var notNeedEnable$1 = "无需启用";
|
|
1634
|
+
var needEnable$1 = "请启用";
|
|
1635
|
+
var securityConnectionMessage$1 = "在通过安全连接时,{{enable}}服务器证书验证,并使用客户端版本 {{version}} ,指定握手路径为 {{path}} 。";
|
|
1636
|
+
var wsConfigMessage$1 = "在通过安全连接时,{{enable}}服务器证书验证,并且允许接收的最大發送内容为{{content}}。";
|
|
1637
|
+
var unlimited$1 = "无限制";
|
|
1638
|
+
var left$1 = "左";
|
|
1639
|
+
var right$1 = "右";
|
|
1640
|
+
var tcpMethodMessage$1 = "{{direction}}填充至长度{{size}},填充字符为:{{str}}";
|
|
1641
|
+
var tcpMethodDelimiterMessage$1 = "结尾添加分隔字符{{str}}";
|
|
1642
|
+
var requestEncodingFormat$1 = "请求报文的编码格式为 {{format}}";
|
|
1643
|
+
var needAddRequestDataHandleFunction$1 = "需要添加请求数据处理函数:";
|
|
1644
|
+
var needAddResponseDataHandleFunction$1 = "需要添加请求数据处理函数:";
|
|
1645
|
+
var addNewline$1 = "在每个请求报文的结尾添加换行符 {{str}}";
|
|
1646
|
+
var addContentLength$1 = "计算内容长度(不包括包头)并将其添加到包头(文本格式,包头字节长度为 {{size}})";
|
|
1647
|
+
var removeResponseHeader$1 = "响应报文需要去除包头(长度为 {{size}} 字节)";
|
|
1648
|
+
var trimTrailingNewline$1 = "去除行尾的换行符 {{str}}";
|
|
1649
|
+
var convertXmlToJson$1 = "将 XML 格式的内容转换为 JSON 格式。";
|
|
1650
|
+
var specialCharText$1 = "文本类型的报文,包尾含特殊字符 {{str}}";
|
|
1651
|
+
var specialCharBinary$1 = "二进制类型的报文,包尾含特殊字符 {{str}}";
|
|
1652
|
+
var headerBodyFormat$1 = "[包头+包体]格式报文(包头存包体字节长度),包头长度为{{size}}字节";
|
|
1653
|
+
var fixedLength$1 = "报文为固定长度({{size}}字节)";
|
|
1654
|
+
var byte$1 = "字节";
|
|
1655
|
+
var completeOnReceive$1 = "收到数据即认为完成(不处理分包问题)";
|
|
1656
|
+
var serverAddress$1 = "服务端地址";
|
|
1657
|
+
var pktCompletion$1 = "判断报文接收完成方式";
|
|
1658
|
+
var createDir$1 = "新建目录";
|
|
1659
|
+
var createProj$1 = "新建项目";
|
|
1660
|
+
var createEnv$1 = "新建环境";
|
|
1661
|
+
var cn = {
|
|
1662
|
+
securityConnectionMessageNoPath: securityConnectionMessageNoPath$1,
|
|
1663
|
+
notNeedEnable: notNeedEnable$1,
|
|
1664
|
+
needEnable: needEnable$1,
|
|
1665
|
+
securityConnectionMessage: securityConnectionMessage$1,
|
|
1666
|
+
wsConfigMessage: wsConfigMessage$1,
|
|
1667
|
+
unlimited: unlimited$1,
|
|
1668
|
+
left: left$1,
|
|
1669
|
+
right: right$1,
|
|
1670
|
+
tcpMethodMessage: tcpMethodMessage$1,
|
|
1671
|
+
tcpMethodDelimiterMessage: tcpMethodDelimiterMessage$1,
|
|
1672
|
+
requestEncodingFormat: requestEncodingFormat$1,
|
|
1673
|
+
needAddRequestDataHandleFunction: needAddRequestDataHandleFunction$1,
|
|
1674
|
+
needAddResponseDataHandleFunction: needAddResponseDataHandleFunction$1,
|
|
1675
|
+
addNewline: addNewline$1,
|
|
1676
|
+
addContentLength: addContentLength$1,
|
|
1677
|
+
removeResponseHeader: removeResponseHeader$1,
|
|
1678
|
+
trimTrailingNewline: trimTrailingNewline$1,
|
|
1679
|
+
convertXmlToJson: convertXmlToJson$1,
|
|
1680
|
+
specialCharText: specialCharText$1,
|
|
1681
|
+
specialCharBinary: specialCharBinary$1,
|
|
1682
|
+
headerBodyFormat: headerBodyFormat$1,
|
|
1683
|
+
fixedLength: fixedLength$1,
|
|
1684
|
+
byte: byte$1,
|
|
1685
|
+
completeOnReceive: completeOnReceive$1,
|
|
1686
|
+
serverAddress: serverAddress$1,
|
|
1687
|
+
pktCompletion: pktCompletion$1,
|
|
1688
|
+
createDir: createDir$1,
|
|
1689
|
+
createProj: createProj$1,
|
|
1690
|
+
createEnv: createEnv$1
|
|
1691
|
+
};
|
|
1692
|
+
|
|
1693
|
+
var securityConnectionMessageNoPath = "在通過安全連接時,{{enable}}伺服器證書驗證,並使用客戶端版本{{version}},無指定握手路徑。";
|
|
1694
|
+
var notNeedEnable = "無需啟用";
|
|
1695
|
+
var needEnable = "請啟用";
|
|
1696
|
+
var securityConnectionMessage = "在通過安全連接時,{{enable}}伺服器證書驗證,並使用客戶端版本{{version}},指定握手路徑為{{path}}。";
|
|
1697
|
+
var wsConfigMessage = "在通過安全連接時,{{enable}}伺服器證書驗證,並且允許接收的最大發送內容為 {{content}}。";
|
|
1698
|
+
var unlimited = "無限制";
|
|
1699
|
+
var left = "左";
|
|
1700
|
+
var right = "右";
|
|
1701
|
+
var tcpMethodMessage = "{{direction}}填充至長度{{size}},填充字符為:{{str}}";
|
|
1702
|
+
var tcpMethodDelimiterMessage = "結尾添加分隔字符{{str}}";
|
|
1703
|
+
var requestEncodingFormat = "請求報文的編碼格式為 {{format}}";
|
|
1704
|
+
var needAddRequestDataHandleFunction = "需要添加請求數據處理函數:";
|
|
1705
|
+
var needAddResponseDataHandleFunction = "需添加響應數據處理函數:";
|
|
1706
|
+
var addNewline = "在每個請求報文的結尾添加換行符 {{str}}";
|
|
1707
|
+
var addContentLength = "計算內容長度(不包括包頭)並將其添加到包頭(文本格式,包頭字節長度為 {{size}})";
|
|
1708
|
+
var removeResponseHeader = "響應報文需要去除包頭(長度為 {{size}} 字節)";
|
|
1709
|
+
var trimTrailingNewline = "去除行尾的換行符 {{str}}";
|
|
1710
|
+
var convertXmlToJson = "將 XML 格式的內容轉換為 JSON 格式。";
|
|
1711
|
+
var specialCharText = "文本類型的報文,包尾含特殊字符 {{str}}";
|
|
1712
|
+
var specialCharBinary = "二進制類型的報文,包尾含特殊字符 {{str}}";
|
|
1713
|
+
var headerBodyFormat = "[包頭+包體]格式報文(包頭存包體字節長度),包頭長度為{{size}}字節";
|
|
1714
|
+
var fixedLength = "報文為固定長度({{size}}字節)";
|
|
1715
|
+
var byte = "位元組";
|
|
1716
|
+
var completeOnReceive = "收到數據即認為完成(不處理分包問題)";
|
|
1717
|
+
var serverAddress = "伺服器地址";
|
|
1718
|
+
var pktCompletion = "判斷報文接收完成方式";
|
|
1719
|
+
var createDir = "新建目錄";
|
|
1720
|
+
var createProj = "新建項目";
|
|
1721
|
+
var createEnv = "新建環境";
|
|
1722
|
+
var tw = {
|
|
1723
|
+
securityConnectionMessageNoPath: securityConnectionMessageNoPath,
|
|
1724
|
+
notNeedEnable: notNeedEnable,
|
|
1725
|
+
needEnable: needEnable,
|
|
1726
|
+
securityConnectionMessage: securityConnectionMessage,
|
|
1727
|
+
wsConfigMessage: wsConfigMessage,
|
|
1728
|
+
unlimited: unlimited,
|
|
1729
|
+
left: left,
|
|
1730
|
+
right: right,
|
|
1731
|
+
tcpMethodMessage: tcpMethodMessage,
|
|
1732
|
+
tcpMethodDelimiterMessage: tcpMethodDelimiterMessage,
|
|
1733
|
+
requestEncodingFormat: requestEncodingFormat,
|
|
1734
|
+
needAddRequestDataHandleFunction: needAddRequestDataHandleFunction,
|
|
1735
|
+
needAddResponseDataHandleFunction: needAddResponseDataHandleFunction,
|
|
1736
|
+
addNewline: addNewline,
|
|
1737
|
+
addContentLength: addContentLength,
|
|
1738
|
+
removeResponseHeader: removeResponseHeader,
|
|
1739
|
+
trimTrailingNewline: trimTrailingNewline,
|
|
1740
|
+
convertXmlToJson: convertXmlToJson,
|
|
1741
|
+
specialCharText: specialCharText,
|
|
1742
|
+
specialCharBinary: specialCharBinary,
|
|
1743
|
+
headerBodyFormat: headerBodyFormat,
|
|
1744
|
+
fixedLength: fixedLength,
|
|
1745
|
+
byte: byte,
|
|
1746
|
+
completeOnReceive: completeOnReceive,
|
|
1747
|
+
serverAddress: serverAddress,
|
|
1748
|
+
pktCompletion: pktCompletion,
|
|
1749
|
+
createDir: createDir,
|
|
1750
|
+
createProj: createProj,
|
|
1751
|
+
createEnv: createEnv
|
|
1752
|
+
};
|
|
1753
|
+
|
|
1754
|
+
let i18nInstance = null;
|
|
1755
|
+
const resources = {
|
|
1756
|
+
"zh-cn": {
|
|
1757
|
+
translation: cn,
|
|
1758
|
+
},
|
|
1759
|
+
en: {
|
|
1760
|
+
translation: en,
|
|
1761
|
+
},
|
|
1762
|
+
ja: {
|
|
1763
|
+
translation: ja,
|
|
1764
|
+
},
|
|
1765
|
+
tw: {
|
|
1766
|
+
translation: tw,
|
|
1767
|
+
},
|
|
1768
|
+
id: {
|
|
1769
|
+
translation: id,
|
|
1770
|
+
},
|
|
1460
1771
|
};
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1772
|
+
/**
|
|
1773
|
+
* 获取或创建独立的 i18next 实例
|
|
1774
|
+
* @returns {i18next.i18n} - i18next 实例
|
|
1775
|
+
*/
|
|
1776
|
+
const I18nInit = (lng) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1777
|
+
// language= lng;
|
|
1778
|
+
if (lng === 'zh-hant') {
|
|
1779
|
+
lng = 'tw';
|
|
1780
|
+
}
|
|
1781
|
+
if (!i18nInstance) {
|
|
1782
|
+
i18nInstance = i18next__default["default"].createInstance();
|
|
1783
|
+
yield i18nInstance.init({
|
|
1784
|
+
lng: lng,
|
|
1785
|
+
fallbackLng: 'zh-cn',
|
|
1786
|
+
resources,
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
else {
|
|
1790
|
+
yield (i18nInstance === null || i18nInstance === void 0 ? void 0 : i18nInstance.changeLanguage(lng));
|
|
1791
|
+
}
|
|
1792
|
+
return i18nInstance;
|
|
1793
|
+
});
|
|
1794
|
+
/**
|
|
1795
|
+
* 根据语言和键获取翻译
|
|
1796
|
+
* @param {string} lng - 语言代码,例如 'en', 'zh'
|
|
1797
|
+
* @param {string} key - 翻译键,例如 'greeting'
|
|
1798
|
+
*/
|
|
1799
|
+
const t = (key, data) => {
|
|
1800
|
+
let result = i18nInstance.t(key, data);
|
|
1801
|
+
return result || key;
|
|
1464
1802
|
};
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1803
|
+
|
|
1804
|
+
// @ts-nocheck
|
|
1805
|
+
const MAX_DEEP_COUNT = 10;
|
|
1806
|
+
const schemaPath = (name, version) => {
|
|
1807
|
+
if (version === '2.0') {
|
|
1808
|
+
return `#/definitions/${name}`;
|
|
1470
1809
|
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1810
|
+
return `#/components/schemas/${name}`;
|
|
1811
|
+
};
|
|
1812
|
+
const deepModelRef = (originSchema, schemaMap, startSchema, count = 0) => {
|
|
1813
|
+
var _a, _b;
|
|
1814
|
+
try {
|
|
1815
|
+
let deepCount = lodash.cloneDeep(count);
|
|
1816
|
+
const schema = lodash.cloneDeep(originSchema);
|
|
1817
|
+
if (lodash.has(schema, 'x-schema-refs')) {
|
|
1818
|
+
const refsValue = schema === null || schema === void 0 ? void 0 : schema['x-schema-refs'];
|
|
1819
|
+
if (!lodash.isEmpty(refsValue) &&
|
|
1820
|
+
Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]') {
|
|
1821
|
+
const properties = Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]'
|
|
1822
|
+
? schema === null || schema === void 0 ? void 0 : schema.properties
|
|
1823
|
+
: {};
|
|
1824
|
+
schema['properties'] = (_a = lodash.values(refsValue)) === null || _a === void 0 ? void 0 : _a.reduce((pre, item) => {
|
|
1825
|
+
var _a, _b;
|
|
1826
|
+
let refId = '';
|
|
1827
|
+
let refPath = item === null || item === void 0 ? void 0 : item.$ref;
|
|
1828
|
+
if (lodash.isString(refPath)) {
|
|
1829
|
+
refId = refPath.split('/').pop() || '';
|
|
1830
|
+
}
|
|
1831
|
+
if (refId &&
|
|
1832
|
+
lodash.has(schemaMap, refId) &&
|
|
1833
|
+
!lodash.isEqual(startSchema || originSchema, (_a = schemaMap[refId]) === null || _a === void 0 ? void 0 : _a.schema)) {
|
|
1834
|
+
const mapValue = schemaMap[refId];
|
|
1835
|
+
if (mapValue && (mapValue === null || mapValue === void 0 ? void 0 : mapValue.name)) {
|
|
1836
|
+
// 暂时没找到多ref引用的方案 先直接导出数据
|
|
1837
|
+
// pre[mapValue?.name] = {
|
|
1838
|
+
// $ref: mapValue?.path,
|
|
1839
|
+
// };
|
|
1840
|
+
let mapSchema = mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema;
|
|
1841
|
+
if (lodash.has(mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema, 'x-schema-refs')) {
|
|
1842
|
+
if (deepCount > MAX_DEEP_COUNT) {
|
|
1843
|
+
mapSchema = mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema;
|
|
1844
|
+
}
|
|
1845
|
+
else {
|
|
1846
|
+
mapSchema = deepModelRef(mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema, schemaMap, startSchema || originSchema, ++deepCount);
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
pre = Object.assign(Object.assign({}, pre), ((mapSchema === null || mapSchema === void 0 ? void 0 : mapSchema.properties) || {}));
|
|
1850
|
+
}
|
|
1851
|
+
if (lodash.isEqual(startSchema || originSchema, (_b = schemaMap[refId]) === null || _b === void 0 ? void 0 : _b.schema)) {
|
|
1852
|
+
pre = {};
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
return pre;
|
|
1856
|
+
}, properties);
|
|
1481
1857
|
}
|
|
1482
|
-
restfulList.push({
|
|
1483
|
-
param_id: (obj === null || obj === void 0 ? void 0 : obj.param_id) || apipostTools.snowflakeId(),
|
|
1484
|
-
field_type: "String",
|
|
1485
|
-
is_checked: 1,
|
|
1486
|
-
key: pathsItem.substring(1, pathsItem.length),
|
|
1487
|
-
not_null: 1,
|
|
1488
|
-
value: (obj === null || obj === void 0 ? void 0 : obj.example) || "",
|
|
1489
|
-
description: (obj === null || obj === void 0 ? void 0 : obj.desc) || "",
|
|
1490
|
-
});
|
|
1491
1858
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
if (
|
|
1505
|
-
|
|
1859
|
+
if (lodash.has(schema, 'properties') &&
|
|
1860
|
+
Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]') {
|
|
1861
|
+
let properties_keys = lodash.keys(schema === null || schema === void 0 ? void 0 : schema.properties);
|
|
1862
|
+
if (
|
|
1863
|
+
// 优化展示顺序
|
|
1864
|
+
(schema === null || schema === void 0 ? void 0 : schema['x-schema-orders']) &&
|
|
1865
|
+
lodash.isArray(schema === null || schema === void 0 ? void 0 : schema['x-schema-orders']) &&
|
|
1866
|
+
lodash.isEqual(lodash.sortBy(schema === null || schema === void 0 ? void 0 : schema['x-schema-orders']), lodash.sortBy(lodash.keys(schema === null || schema === void 0 ? void 0 : schema.properties)))) {
|
|
1867
|
+
properties_keys = schema === null || schema === void 0 ? void 0 : schema['x-schema-orders'];
|
|
1868
|
+
}
|
|
1869
|
+
schema['properties'] = properties_keys === null || properties_keys === void 0 ? void 0 : properties_keys.reduce((pre, key) => {
|
|
1870
|
+
if (key && !lodash.isEmpty(schema === null || schema === void 0 ? void 0 : schema.properties[key])) {
|
|
1871
|
+
if (deepCount > MAX_DEEP_COUNT) {
|
|
1872
|
+
pre[key] = schema === null || schema === void 0 ? void 0 : schema.properties[key];
|
|
1873
|
+
}
|
|
1874
|
+
else {
|
|
1875
|
+
pre[key] = deepModelRef(schema === null || schema === void 0 ? void 0 : schema.properties[key], schemaMap, startSchema || originSchema, ++deepCount);
|
|
1506
1876
|
}
|
|
1507
|
-
restfulList.push({
|
|
1508
|
-
param_id: (obj === null || obj === void 0 ? void 0 : obj.param_id) || apipostTools.snowflakeId(),
|
|
1509
|
-
field_type: "String",
|
|
1510
|
-
is_checked: 1,
|
|
1511
|
-
key: matchesItem,
|
|
1512
|
-
not_null: 1,
|
|
1513
|
-
value: (obj === null || obj === void 0 ? void 0 : obj.example) || "",
|
|
1514
|
-
description: (obj === null || obj === void 0 ? void 0 : obj.desc) || "",
|
|
1515
|
-
});
|
|
1516
1877
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
}
|
|
1520
|
-
catch (error) { }
|
|
1521
|
-
return restfulList;
|
|
1522
|
-
};
|
|
1523
|
-
const fixUrlPath = (url) => {
|
|
1524
|
-
try {
|
|
1525
|
-
const index = url.indexOf("://");
|
|
1526
|
-
let path;
|
|
1527
|
-
let protocolAndDomain = "";
|
|
1528
|
-
if (index === -1) {
|
|
1529
|
-
path = url;
|
|
1878
|
+
return pre;
|
|
1879
|
+
}, {});
|
|
1530
1880
|
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1881
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' && lodash.has(schema, 'items')) {
|
|
1882
|
+
if (lodash.has(schema === null || schema === void 0 ? void 0 : schema.items, 'properties') &&
|
|
1883
|
+
Object.prototype.toString.call((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.properties) === '[object Object]') {
|
|
1884
|
+
if (deepCount <= MAX_DEEP_COUNT) {
|
|
1885
|
+
schema.items = deepModelRef(schema === null || schema === void 0 ? void 0 : schema.items, schemaMap, startSchema || originSchema, ++deepCount);
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1535
1888
|
}
|
|
1536
|
-
//
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
return
|
|
1889
|
+
// 处理数组的引用
|
|
1890
|
+
schema === null || schema === void 0 ? true : delete schema['x-schema-orders'];
|
|
1891
|
+
schema === null || schema === void 0 ? true : delete schema['x-schema-refs'];
|
|
1892
|
+
return schema;
|
|
1540
1893
|
}
|
|
1541
1894
|
catch (err) {
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
};
|
|
1545
|
-
const anyToString = (desc) => {
|
|
1546
|
-
if (lodash.isString(desc)) {
|
|
1547
|
-
return desc;
|
|
1548
|
-
}
|
|
1549
|
-
if (lodash.isNumber(desc)) {
|
|
1550
|
-
return desc.toString();
|
|
1551
|
-
}
|
|
1552
|
-
if (lodash.isPlainObject(desc) || isArray(desc)) {
|
|
1553
|
-
return JSON.stringify(desc);
|
|
1895
|
+
console.log(err.message, "deepModelRef error");
|
|
1896
|
+
return originSchema;
|
|
1554
1897
|
}
|
|
1555
|
-
return String(desc);
|
|
1556
1898
|
};
|
|
1557
|
-
const
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1899
|
+
// export const deepHandleModelRef = (
|
|
1900
|
+
// modelObj: any,
|
|
1901
|
+
// modelsObj: any,
|
|
1902
|
+
// version: string
|
|
1903
|
+
// ) => {
|
|
1904
|
+
// const result = modelObj;
|
|
1905
|
+
// // 遍历所有属性
|
|
1906
|
+
// for (const key in modelObj) {
|
|
1907
|
+
// if (has(modelObj, key)) {
|
|
1908
|
+
// const value = modelObj[key];
|
|
1909
|
+
// // 如果属性名为 "APIPOST_REFS"
|
|
1910
|
+
// if (key === "APIPOST_REFS") {
|
|
1911
|
+
// const lonely =
|
|
1912
|
+
// !has(modelObj, "properties") || isEmpty(modelObj.properties);
|
|
1913
|
+
// if (isPlainObject(value) && !isEmpty(value)) {
|
|
1914
|
+
// const refArr: any = Object.keys(value);
|
|
1915
|
+
// let modelPath = "";
|
|
1916
|
+
// if (refArr.length > 1) {
|
|
1917
|
+
// if (!has(modelObj, "properties")) {
|
|
1918
|
+
// modelObj.properties = {};
|
|
1919
|
+
// }
|
|
1920
|
+
// refArr.forEach((item: any) => {
|
|
1921
|
+
// const modelObjItem = modelsObj?.[value?.[item]?.ref];
|
|
1922
|
+
// modelPath = splicedPath(modelObjItem?.modelPath, version);
|
|
1923
|
+
// modelObj.properties["$ref"] = modelPath;
|
|
1924
|
+
// });
|
|
1925
|
+
// } else {
|
|
1926
|
+
// const oldRef = value?.[refArr[0]]?.ref;
|
|
1927
|
+
// const hasInvPath = modelsObj?.[oldRef]?.modelPath;
|
|
1928
|
+
// let modelPath = splicedPath(
|
|
1929
|
+
// modelsObj?.[oldRef]?.modelPath,
|
|
1930
|
+
// version
|
|
1931
|
+
// );
|
|
1932
|
+
// if (lonely && hasInvPath) {
|
|
1933
|
+
// modelObj.$ref = modelPath;
|
|
1934
|
+
// } else {
|
|
1935
|
+
// refArr.forEach((item: any) => {
|
|
1936
|
+
// const modelObjItem = modelsObj?.[value?.[item]?.ref];
|
|
1937
|
+
// modelPath = splicedPath(modelObjItem?.modelPath, version);
|
|
1938
|
+
// modelObj.properties["$ref"] = modelPath;
|
|
1939
|
+
// });
|
|
1940
|
+
// }
|
|
1941
|
+
// }
|
|
1942
|
+
// }
|
|
1943
|
+
// }
|
|
1944
|
+
// // 如果属性是一个对象,就递归查找
|
|
1945
|
+
// else if (
|
|
1946
|
+
// Object.prototype.toString.call(value) === "[object Object]" &&
|
|
1947
|
+
// value !== null
|
|
1948
|
+
// ) {
|
|
1949
|
+
// modelObj[key] = deepHandleModelRef(value, modelsObj, version);
|
|
1950
|
+
// }
|
|
1951
|
+
// }
|
|
1952
|
+
// }
|
|
1953
|
+
// return result;
|
|
1954
|
+
// };
|
|
1955
|
+
const removeQuery = (url) => {
|
|
1956
|
+
let path = url;
|
|
1957
|
+
try {
|
|
1958
|
+
const parts = url.split("?");
|
|
1959
|
+
path = parts[0];
|
|
1562
1960
|
}
|
|
1563
|
-
|
|
1961
|
+
catch (error) { }
|
|
1962
|
+
return path || "/";
|
|
1564
1963
|
};
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
let newUrl = url || "";
|
|
1570
|
-
const handleEncode = (value = "") => {
|
|
1571
|
-
let _value = lodash.cloneDeep(value);
|
|
1572
|
-
try {
|
|
1573
|
-
// 将#符号encode
|
|
1574
|
-
_value = _value.replace(/#/g, encodeURIComponent("#"));
|
|
1575
|
-
// 将&符号encode
|
|
1576
|
-
_value = _value.replace(/&/g, encodeURIComponent("&"));
|
|
1964
|
+
const recursiveFolderPath = (path, sourceObj, pid, pidName = "pid") => {
|
|
1965
|
+
if (pid && sourceObj[pid]) {
|
|
1966
|
+
if (path) {
|
|
1967
|
+
path = `${sourceObj[pid].name}/${path}`;
|
|
1577
1968
|
}
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
};
|
|
1581
|
-
lodash.forEach(parameter, (item) => {
|
|
1582
|
-
if (item.key && lodash.isEqual(item.is_checked, 1)) {
|
|
1583
|
-
paramsStr += `${paramsStr ? "&" : ""}${handleEncode(item.key)}${lodash.isEqual(query_add_equal, -1) && !item.value ? "" : "="}${handleEncode(item.value)}`;
|
|
1969
|
+
else {
|
|
1970
|
+
path = sourceObj[pid].name;
|
|
1584
1971
|
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
return newUrl;
|
|
1589
|
-
};
|
|
1590
|
-
const getSubstring = (str, length) => {
|
|
1591
|
-
if (lodash.isString(str)) {
|
|
1592
|
-
return str.substring(0, length);
|
|
1972
|
+
if (sourceObj[pid][pidName] && sourceObj[pid][pidName] != "0")
|
|
1973
|
+
return recursiveFolderPath(path, sourceObj, sourceObj[pid][pidName], pidName);
|
|
1974
|
+
return path;
|
|
1593
1975
|
}
|
|
1594
|
-
return
|
|
1976
|
+
return path;
|
|
1595
1977
|
};
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
Object.defineProperty(this, "apiToSwaggerResult", {
|
|
1606
|
-
enumerable: true,
|
|
1607
|
-
configurable: true,
|
|
1608
|
-
writable: true,
|
|
1609
|
-
value: void 0
|
|
1610
|
-
});
|
|
1611
|
-
Object.defineProperty(this, "apiToSwaggerVersion", {
|
|
1612
|
-
enumerable: true,
|
|
1613
|
-
configurable: true,
|
|
1614
|
-
writable: true,
|
|
1615
|
-
value: void 0
|
|
1616
|
-
});
|
|
1617
|
-
this.apiToSwaggerOrigin = {};
|
|
1618
|
-
this.apiToSwaggerResult = {};
|
|
1619
|
-
this.apiToSwaggerVersion = "2.0";
|
|
1620
|
-
}
|
|
1621
|
-
handleProject() {
|
|
1622
|
-
const { name, intro, marks, attributes } = this.apiToSwaggerOrigin.project || {};
|
|
1623
|
-
this.apiToSwaggerResult.info = {
|
|
1624
|
-
title: name || t('createProj'),
|
|
1625
|
-
description: intro || "",
|
|
1626
|
-
version: "1.0.0",
|
|
1627
|
-
};
|
|
1628
|
-
if (this.apiToSwaggerVersion == "2.0") {
|
|
1629
|
-
this.apiToSwaggerResult.swagger = "2.0";
|
|
1630
|
-
}
|
|
1631
|
-
else if (this.apiToSwaggerVersion == "3.0") {
|
|
1632
|
-
this.apiToSwaggerResult.openapi = "3.0.0";
|
|
1633
|
-
}
|
|
1634
|
-
if (lodash.isArray(marks) && marks.length > 0) {
|
|
1635
|
-
this.apiToSwaggerResult.info['x-marks'] = marks;
|
|
1636
|
-
}
|
|
1637
|
-
if (lodash.isArray(attributes) && attributes.length > 0) {
|
|
1638
|
-
this.apiToSwaggerResult.info['x-attributes'] = attributes;
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
handleModels() {
|
|
1642
|
-
var _a, _b;
|
|
1643
|
-
const version = this.apiToSwaggerVersion;
|
|
1644
|
-
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");
|
|
1645
|
-
// 声明一个schema映射表
|
|
1646
|
-
const schemaMap = childModels === null || childModels === void 0 ? void 0 : childModels.reduce((pre, item) => {
|
|
1647
|
-
if ((item === null || item === void 0 ? void 0 : item.model_id) && (item === null || item === void 0 ? void 0 : item.name)) {
|
|
1648
|
-
pre[item === null || item === void 0 ? void 0 : item.model_id] = {
|
|
1649
|
-
schema: (item === null || item === void 0 ? void 0 : item.schema) || { type: 'object', properties: {} },
|
|
1650
|
-
path: schemaPath(item === null || item === void 0 ? void 0 : item.name, version),
|
|
1651
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || '',
|
|
1978
|
+
const generateProperties = (objStr) => {
|
|
1979
|
+
const ret = {};
|
|
1980
|
+
try {
|
|
1981
|
+
const obj = JSON.parse(objStr);
|
|
1982
|
+
for (const key in obj) {
|
|
1983
|
+
if (lodash.isPlainObject(obj[key])) {
|
|
1984
|
+
ret[key] = {
|
|
1985
|
+
type: "object",
|
|
1986
|
+
properties: generateProperties(JSON.stringify(obj[key])),
|
|
1652
1987
|
};
|
|
1653
1988
|
}
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
pre[item === null || item === void 0 ? void 0 : item.name] = deepModelRef(item === null || item === void 0 ? void 0 : item.schema, schemaMap);
|
|
1660
|
-
}
|
|
1661
|
-
return pre;
|
|
1662
|
-
}, {});
|
|
1663
|
-
// 先不区分目录概念 把所有的schema都放在schemas目录下 后期加上schemas生成多目录
|
|
1664
|
-
if (version === '2.0') {
|
|
1665
|
-
this.apiToSwaggerResult.definitions = schemas;
|
|
1666
|
-
}
|
|
1667
|
-
if (lodash.isEqual(version, '3.0') || lodash.isEqual(version, '3.0.0')) {
|
|
1668
|
-
this.apiToSwaggerResult.components = { schemas };
|
|
1989
|
+
else if (obj[key]) {
|
|
1990
|
+
ret[key] = {
|
|
1991
|
+
type: typeof obj[key] === "number" ? "integer" : typeof obj[key],
|
|
1992
|
+
example: obj[key],
|
|
1993
|
+
};
|
|
1669
1994
|
}
|
|
1670
1995
|
}
|
|
1671
|
-
return schemaMap;
|
|
1672
1996
|
}
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1997
|
+
catch (e) { }
|
|
1998
|
+
return ret;
|
|
1999
|
+
};
|
|
2000
|
+
const formatTags = (tag = "") => {
|
|
2001
|
+
return tag.split("/") || [];
|
|
2002
|
+
};
|
|
2003
|
+
const handlePathItemParameters = (type, arr, pathItem) => {
|
|
2004
|
+
var _a;
|
|
2005
|
+
if (lodash.isArray(arr) && arr.length > 0) {
|
|
2006
|
+
if (!lodash.has(pathItem, "parameters")) {
|
|
2007
|
+
pathItem.parameters = [];
|
|
2008
|
+
}
|
|
2009
|
+
for (const item of arr) {
|
|
2010
|
+
if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
|
|
2011
|
+
item.key.length > 0 &&
|
|
2012
|
+
(!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
|
|
2013
|
+
pathItem.parameters.push({
|
|
2014
|
+
name: item.key,
|
|
2015
|
+
in: type,
|
|
2016
|
+
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
2017
|
+
required: (item === null || item === void 0 ? void 0 : item.not_null) === 1,
|
|
2018
|
+
example: String((item === null || item === void 0 ? void 0 : item.value) || ""),
|
|
2019
|
+
schema: Object.assign({ type: (_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase() }, ((item === null || item === void 0 ? void 0 : item.schema) || {})),
|
|
2020
|
+
});
|
|
1693
2021
|
}
|
|
1694
2022
|
}
|
|
1695
2023
|
}
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
2024
|
+
};
|
|
2025
|
+
const handlePathItemBodyParameters = (body, pathItem, modelsObj) => {
|
|
2026
|
+
if (lodash.isPlainObject(body) && !lodash.isEmpty(body) && (body === null || body === void 0 ? void 0 : body.mode) != "none") {
|
|
2027
|
+
if (!lodash.has(pathItem, "parameters")) {
|
|
2028
|
+
pathItem.parameters = [];
|
|
2029
|
+
}
|
|
2030
|
+
const mode = MODE_TYPE[body === null || body === void 0 ? void 0 : body.mode];
|
|
2031
|
+
if (lodash.isString(mode) && mode.length > 0) {
|
|
2032
|
+
if ([
|
|
2033
|
+
"application/json",
|
|
2034
|
+
"application/xml",
|
|
2035
|
+
"application/javascript",
|
|
2036
|
+
"text/plain",
|
|
2037
|
+
"text/html",
|
|
2038
|
+
].includes(mode)) {
|
|
2039
|
+
let obj = {
|
|
2040
|
+
in: "body",
|
|
2041
|
+
name: "body",
|
|
2042
|
+
description: "",
|
|
2043
|
+
schema: deepModelRef((body === null || body === void 0 ? void 0 : body.raw_schema) || {
|
|
2044
|
+
type: 'object'
|
|
2045
|
+
}, modelsObj),
|
|
2046
|
+
type: "string",
|
|
2047
|
+
example: (body === null || body === void 0 ? void 0 : body.raw) || "",
|
|
2048
|
+
};
|
|
2049
|
+
pathItem.parameters.push(obj);
|
|
2050
|
+
}
|
|
2051
|
+
else if (["multipart/form-data", "application/x-www-form-urlencoded"].includes(mode)) {
|
|
2052
|
+
const parameter = (body === null || body === void 0 ? void 0 : body.parameter) || [];
|
|
2053
|
+
if (lodash.isArray(parameter) && parameter.length > 0) {
|
|
2054
|
+
parameter.forEach((item) => {
|
|
2055
|
+
if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
|
|
2056
|
+
item.key.length > 0 &&
|
|
2057
|
+
(!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
|
|
2058
|
+
pathItem.parameters.push({
|
|
2059
|
+
in: "formData",
|
|
2060
|
+
name: item.key,
|
|
2061
|
+
type: "string",
|
|
2062
|
+
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
2063
|
+
default: (item === null || item === void 0 ? void 0 : item.value) || "",
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
1727
2068
|
}
|
|
1728
2069
|
}
|
|
1729
|
-
return Object.assign(Object.assign({}, item), { tags: formatTags(tags[0]) });
|
|
1730
2070
|
}
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
2071
|
+
};
|
|
2072
|
+
const handleGraphqlRequestBody = (query_list, query_schema, pathItem, modelsObj) => {
|
|
2073
|
+
if (lodash.isArray(query_list) && query_list.length > 0) {
|
|
2074
|
+
if (!lodash.has(pathItem, "requestBody")) {
|
|
2075
|
+
pathItem.requestBody = {
|
|
2076
|
+
content: {},
|
|
2077
|
+
'x-schema': query_schema || {}
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
query_list.forEach(m => {
|
|
2081
|
+
var _a, _b, _c;
|
|
2082
|
+
const mode = `x-${m === null || m === void 0 ? void 0 : m.param_id}`;
|
|
2083
|
+
pathItem.requestBody.content[mode] = {
|
|
2084
|
+
'x-query': (m === null || m === void 0 ? void 0 : m.query) || '',
|
|
2085
|
+
'x-variables': (m === null || m === void 0 ? void 0 : m.variables) || '',
|
|
2086
|
+
'x-summary': (m === null || m === void 0 ? void 0 : m.name) || '',
|
|
2087
|
+
'x-response': {
|
|
2088
|
+
'x-mode': ((_a = m === null || m === void 0 ? void 0 : m.response) === null || _a === void 0 ? void 0 : _a.mode) || '',
|
|
2089
|
+
example: ((_b = m === null || m === void 0 ? void 0 : m.response) === null || _b === void 0 ? void 0 : _b.raw) || "",
|
|
2090
|
+
schema: deepModelRef(((_c = m === null || m === void 0 ? void 0 : m.response) === null || _c === void 0 ? void 0 : _c.raw_schema) || {
|
|
2091
|
+
type: "object",
|
|
2092
|
+
}, modelsObj),
|
|
2093
|
+
}
|
|
2094
|
+
};
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2098
|
+
const handleSocketMethodParameterDescription = (item, mode) => {
|
|
2099
|
+
let description = item === null || item === void 0 ? void 0 : item.description;
|
|
2100
|
+
let rules = item === null || item === void 0 ? void 0 : item.rules;
|
|
2101
|
+
if (mode == 'fixed_message') {
|
|
2102
|
+
return `${description}\n${t('tcpMethodMessage', {
|
|
2103
|
+
direction: (rules === null || rules === void 0 ? void 0 : rules.fill_type) == 'left' ? t('left') : (rules === null || rules === void 0 ? void 0 : rules.fill_type) == 'right' ? t('right') : '',
|
|
2104
|
+
size: rules === null || rules === void 0 ? void 0 : rules.length,
|
|
2105
|
+
str: (rules === null || rules === void 0 ? void 0 : rules.content_type) == 'common' ? RULE_TYPES[rules === null || rules === void 0 ? void 0 : rules.common] : rules === null || rules === void 0 ? void 0 : rules.custom
|
|
2106
|
+
})}`;
|
|
2107
|
+
}
|
|
2108
|
+
else if (mode == 'delimiter_message') {
|
|
2109
|
+
return `${description}\n${t('tcpMethodDelimiterMessage', {
|
|
2110
|
+
str: RULE_TYPES_ICON[rules === null || rules === void 0 ? void 0 : rules.delimiter]
|
|
2111
|
+
})}`;
|
|
2112
|
+
}
|
|
2113
|
+
return description;
|
|
2114
|
+
};
|
|
2115
|
+
const handleSocketMethodRequestBody = (body, pathItem) => {
|
|
2116
|
+
if (lodash.isPlainObject(body) && !lodash.isEmpty(body)) {
|
|
2117
|
+
if (!lodash.has(pathItem, "requestBody")) {
|
|
2118
|
+
pathItem.requestBody = {
|
|
2119
|
+
content: {},
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
const mode = MODE_TYPE[body === null || body === void 0 ? void 0 : body.mode];
|
|
2123
|
+
const parameter = (body === null || body === void 0 ? void 0 : body.parameter) || [];
|
|
2124
|
+
if (['delimiter_message', 'fixed_message'].includes(body === null || body === void 0 ? void 0 : body.mode)) {
|
|
2125
|
+
pathItem.requestBody.content[body === null || body === void 0 ? void 0 : body.mode] = {
|
|
2126
|
+
'x-mode': (body === null || body === void 0 ? void 0 : body.mode) || '',
|
|
2127
|
+
schema: {
|
|
2128
|
+
type: "object",
|
|
2129
|
+
properties: parameter.reduce((lastData, item) => {
|
|
2130
|
+
if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
|
|
2131
|
+
item.key.length > 0 &&
|
|
2132
|
+
(!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
|
|
2133
|
+
lastData[item.key] = {
|
|
2134
|
+
type: "string",
|
|
2135
|
+
description: handleSocketMethodParameterDescription(item, body === null || body === void 0 ? void 0 : body.mode),
|
|
2136
|
+
example: (item === null || item === void 0 ? void 0 : item.value) || "",
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
return lastData;
|
|
2140
|
+
}, {}),
|
|
2141
|
+
},
|
|
2142
|
+
example: "",
|
|
2143
|
+
};
|
|
2144
|
+
}
|
|
2145
|
+
else {
|
|
2146
|
+
if (mode) {
|
|
2147
|
+
pathItem.requestBody.content[mode] = {
|
|
2148
|
+
'x-mode': mode || '',
|
|
2149
|
+
schema: lodash.isPlainObject(body === null || body === void 0 ? void 0 : body.raw_schema) && !lodash.isEmpty(body === null || body === void 0 ? void 0 : body.raw_schema) ? body === null || body === void 0 ? void 0 : body.raw_schema : {
|
|
2150
|
+
type: "object",
|
|
2151
|
+
},
|
|
2152
|
+
example: (body === null || body === void 0 ? void 0 : body.raw) || "",
|
|
1742
2153
|
};
|
|
1743
2154
|
}
|
|
1744
2155
|
}
|
|
1745
|
-
this.apiToSwaggerResult.paths = tempPaths;
|
|
1746
2156
|
}
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
}
|
|
1772
|
-
else if (pathItem.tags.length > 0) {
|
|
1773
|
-
lodash.forEach(pathItem.tags, tag => {
|
|
1774
|
-
if (!paths[temp_url][targetMethod].tags.includes(tag)) {
|
|
1775
|
-
// 排除重复目录
|
|
1776
|
-
paths[temp_url][targetMethod].tags.push(tag);
|
|
1777
|
-
}
|
|
1778
|
-
});
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
else if (["folder", "socket"].includes(item.target_type)) {
|
|
1782
|
-
const path = recursiveFolderPath(`${item === null || item === void 0 ? void 0 : item.name}`, sourceObj, pid, pidName);
|
|
1783
|
-
item.path = path;
|
|
1784
|
-
if (!lodash.has(folderObj, item === null || item === void 0 ? void 0 : item.name)) {
|
|
1785
|
-
if (!this.apiToSwaggerResult.tags) {
|
|
1786
|
-
this.apiToSwaggerResult.tags = [];
|
|
1787
|
-
}
|
|
1788
|
-
// 收到数据即认为完成(不处理分包问题) none
|
|
1789
|
-
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)) {
|
|
1790
|
-
if (!(folderObj === null || folderObj === void 0 ? void 0 : folderObj[item === null || item === void 0 ? void 0 : item.name])) {
|
|
1791
|
-
item.description = `| ${t('serverAddress')} | ${t('pktCompletion')} |
|
|
1792
|
-
| --- | --- |
|
|
1793
|
-
| ${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)}
|
|
1794
|
-
${item.description}
|
|
1795
|
-
`;
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
this.apiToSwaggerResult.tags.push({
|
|
1799
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || t('createDir'),
|
|
1800
|
-
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
1801
|
-
'x-type': item.target_type,
|
|
1802
|
-
'x-url': (item === null || item === void 0 ? void 0 : item.url) || '',
|
|
1803
|
-
'x-target-id': (item === null || item === void 0 ? void 0 : item.target_id) || ''
|
|
1804
|
-
});
|
|
1805
|
-
folderObj[item === null || item === void 0 ? void 0 : item.name] = item;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
else if (['websocket2', 'socketio', 'graphql'].includes(item.target_type)) {
|
|
1809
|
-
const temp_url = removeQuery(item === null || item === void 0 ? void 0 : item.url);
|
|
1810
|
-
const targetMethod = `x-${item === null || item === void 0 ? void 0 : item.target_id}`;
|
|
1811
|
-
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
|
|
1812
|
-
if (!paths[temp_url])
|
|
1813
|
-
paths[temp_url] = {};
|
|
1814
|
-
if (!paths[temp_url][targetMethod]) {
|
|
1815
|
-
paths[temp_url][targetMethod] = pathItem;
|
|
1816
|
-
}
|
|
1817
|
-
else if (pathItem.tags.length > 0) {
|
|
1818
|
-
lodash.forEach(pathItem.tags, tag => {
|
|
1819
|
-
if (!paths[temp_url][targetMethod].tags.includes(tag)) {
|
|
1820
|
-
// 排除重复目录
|
|
1821
|
-
paths[temp_url][targetMethod].tags.push(tag);
|
|
1822
|
-
}
|
|
1823
|
-
});
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
else if (item.target_type === 'socket_method') {
|
|
1827
|
-
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}`;
|
|
1828
|
-
const targetMethod = `x-${item.target_id}`;
|
|
1829
|
-
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
|
|
1830
|
-
if (!paths[temp_url])
|
|
1831
|
-
paths[temp_url] = {};
|
|
1832
|
-
if (!paths[temp_url][targetMethod]) {
|
|
1833
|
-
paths[temp_url][targetMethod] = pathItem;
|
|
1834
|
-
}
|
|
1835
|
-
else if (pathItem.tags.length > 0) {
|
|
1836
|
-
lodash.forEach(pathItem.tags, tag => {
|
|
1837
|
-
if (!paths[temp_url][targetMethod].tags.includes(tag)) {
|
|
1838
|
-
// 排除重复目录
|
|
1839
|
-
paths[temp_url][targetMethod].tags.push(tag);
|
|
1840
|
-
}
|
|
1841
|
-
});
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
else if (item.target_type === 'doc') {
|
|
1845
|
-
const temp_url = `x-${item.target_id}`;
|
|
1846
|
-
const targetMethod = `x-${item === null || item === void 0 ? void 0 : item.name}`;
|
|
1847
|
-
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
|
|
1848
|
-
if (!paths[temp_url])
|
|
1849
|
-
paths[temp_url] = {};
|
|
1850
|
-
if (!paths[temp_url][targetMethod]) {
|
|
1851
|
-
paths[temp_url][targetMethod] = pathItem;
|
|
1852
|
-
}
|
|
1853
|
-
else if (pathItem.tags.length > 0) {
|
|
1854
|
-
lodash.forEach(pathItem.tags, tag => {
|
|
1855
|
-
if (!paths[temp_url][targetMethod].tags.includes(tag)) {
|
|
1856
|
-
// 排除重复目录
|
|
1857
|
-
paths[temp_url][targetMethod].tags.push(tag);
|
|
1858
|
-
}
|
|
1859
|
-
});
|
|
1860
|
-
}
|
|
2157
|
+
};
|
|
2158
|
+
const handleMessagePathItemrequestBody = (message, pathItem, modelsObj) => {
|
|
2159
|
+
if (lodash.isArray(message) && message.length > 0) {
|
|
2160
|
+
if (!lodash.has(pathItem, "requestBody")) {
|
|
2161
|
+
pathItem.requestBody = {
|
|
2162
|
+
content: {},
|
|
2163
|
+
};
|
|
2164
|
+
}
|
|
2165
|
+
message.forEach(m => {
|
|
2166
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2167
|
+
const mode = `x-${m === null || m === void 0 ? void 0 : m.param_id}`;
|
|
2168
|
+
pathItem.requestBody.content[mode] = {
|
|
2169
|
+
'x-mode': ((_a = m === null || m === void 0 ? void 0 : m.request) === null || _a === void 0 ? void 0 : _a.mode) || '',
|
|
2170
|
+
'x-summary': (m === null || m === void 0 ? void 0 : m.name) || '',
|
|
2171
|
+
schema: deepModelRef(((_b = m === null || m === void 0 ? void 0 : m.request) === null || _b === void 0 ? void 0 : _b.raw_schema) || {
|
|
2172
|
+
type: "object",
|
|
2173
|
+
}, modelsObj),
|
|
2174
|
+
example: ((_c = m === null || m === void 0 ? void 0 : m.request) === null || _c === void 0 ? void 0 : _c.raw) || "",
|
|
2175
|
+
'x-response': {
|
|
2176
|
+
'x-mode': ((_d = m === null || m === void 0 ? void 0 : m.response) === null || _d === void 0 ? void 0 : _d.mode) || '',
|
|
2177
|
+
example: ((_e = m === null || m === void 0 ? void 0 : m.response) === null || _e === void 0 ? void 0 : _e.raw) || "",
|
|
2178
|
+
schema: deepModelRef(((_f = m === null || m === void 0 ? void 0 : m.response) === null || _f === void 0 ? void 0 : _f.raw_schema) || {
|
|
2179
|
+
type: "object",
|
|
2180
|
+
}, modelsObj),
|
|
1861
2181
|
}
|
|
2182
|
+
};
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
2185
|
+
};
|
|
2186
|
+
const handlePathItemResponse = (response, modelsObj) => {
|
|
2187
|
+
const temp_responses = {};
|
|
2188
|
+
const example = (response === null || response === void 0 ? void 0 : response.example) || [];
|
|
2189
|
+
if (lodash.isPlainObject(response)) {
|
|
2190
|
+
example.forEach(({ expect, raw }) => {
|
|
2191
|
+
const code = expect === null || expect === void 0 ? void 0 : expect.code;
|
|
2192
|
+
if (lodash.isNumber(code) || lodash.isString(code)) {
|
|
2193
|
+
temp_responses[code] = {
|
|
2194
|
+
description: (expect === null || expect === void 0 ? void 0 : expect.name) || "",
|
|
2195
|
+
content: {
|
|
2196
|
+
[(MODE_TYPE === null || MODE_TYPE === void 0 ? void 0 : MODE_TYPE[expect === null || expect === void 0 ? void 0 : expect.content_type]) || "*/*"]: {
|
|
2197
|
+
schema: deepModelRef((expect === null || expect === void 0 ? void 0 : expect.schema) || {}, modelsObj),
|
|
2198
|
+
example: raw || '',
|
|
2199
|
+
},
|
|
2200
|
+
},
|
|
2201
|
+
};
|
|
1862
2202
|
}
|
|
1863
|
-
|
|
1864
|
-
paths,
|
|
1865
|
-
folderObj,
|
|
1866
|
-
};
|
|
1867
|
-
}
|
|
1868
|
-
catch (error) {
|
|
1869
|
-
console.log(error);
|
|
1870
|
-
return {};
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
array2TreeExport(idName = "id", pidName = "pid", modelsObj) {
|
|
1874
|
-
try {
|
|
1875
|
-
const { paths } = this.array2NamePathObj(idName, pidName, modelsObj);
|
|
1876
|
-
this.apiToSwaggerResult.paths = paths;
|
|
1877
|
-
}
|
|
1878
|
-
catch (error) {
|
|
1879
|
-
console.log(error);
|
|
1880
|
-
return [];
|
|
1881
|
-
}
|
|
2203
|
+
});
|
|
1882
2204
|
}
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
2205
|
+
return temp_responses;
|
|
2206
|
+
};
|
|
2207
|
+
const handlePathItemRequestBody = (body, pathItem, modelsObj) => {
|
|
2208
|
+
if (lodash.isPlainObject(body) && !lodash.isEmpty(body) && (body === null || body === void 0 ? void 0 : body.mode) != "none") {
|
|
2209
|
+
if (!lodash.has(pathItem, "requestBody")) {
|
|
2210
|
+
pathItem.requestBody = {
|
|
2211
|
+
content: {},
|
|
2212
|
+
};
|
|
1887
2213
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
2214
|
+
const mode = MODE_TYPE[body === null || body === void 0 ? void 0 : body.mode];
|
|
2215
|
+
if (lodash.isString(mode) && mode.length > 0) {
|
|
2216
|
+
if ([
|
|
2217
|
+
"application/json",
|
|
2218
|
+
"application/xml",
|
|
2219
|
+
"application/javascript",
|
|
2220
|
+
"text/plain",
|
|
2221
|
+
"text/html",
|
|
2222
|
+
].includes(mode)) {
|
|
2223
|
+
pathItem.requestBody.content[mode] = {
|
|
2224
|
+
schema: deepModelRef((body === null || body === void 0 ? void 0 : body.raw_schema) || {
|
|
2225
|
+
type: "object",
|
|
2226
|
+
}, modelsObj),
|
|
2227
|
+
example: (body === null || body === void 0 ? void 0 : body.raw) || "",
|
|
2228
|
+
};
|
|
1898
2229
|
}
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
2230
|
+
else if (["multipart/form-data", "application/x-www-form-urlencoded"].includes(mode)) {
|
|
2231
|
+
const parameter = (body === null || body === void 0 ? void 0 : body.parameter) || [];
|
|
2232
|
+
if (lodash.isArray(parameter) && parameter.length > 0) {
|
|
2233
|
+
pathItem.requestBody.content[mode] = {
|
|
2234
|
+
schema: {
|
|
2235
|
+
type: "object",
|
|
2236
|
+
properties: parameter.reduce((lastData, item) => {
|
|
2237
|
+
var _a;
|
|
2238
|
+
if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
|
|
2239
|
+
item.key.length > 0 &&
|
|
2240
|
+
(!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
|
|
2241
|
+
lastData[item.key] = Object.assign({ type: ((_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || 'string', description: (item === null || item === void 0 ? void 0 : item.description) || "", example: (item === null || item === void 0 ? void 0 : item.value) || "" }, (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.schema) ? item.schema : {}));
|
|
2242
|
+
}
|
|
2243
|
+
return lastData;
|
|
2244
|
+
}, {})
|
|
2245
|
+
},
|
|
2246
|
+
};
|
|
1910
2247
|
}
|
|
1911
|
-
return throwResult$1("success", "", this.apiToSwaggerResult);
|
|
1912
|
-
}
|
|
1913
|
-
catch (error) {
|
|
1914
|
-
console.log(JSON.stringify(error.message), "error");
|
|
1915
|
-
return throwResult$1("error", String(error), this.apiToSwaggerResult);
|
|
1916
2248
|
}
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
|
|
1921
|
-
const getApipostMode = (mode) => {
|
|
1922
|
-
let apipostMode = 'none';
|
|
1923
|
-
if (mode == 'multipart/form-data') {
|
|
1924
|
-
apipostMode = 'form-data';
|
|
2249
|
+
}
|
|
1925
2250
|
}
|
|
1926
|
-
else
|
|
1927
|
-
|
|
2251
|
+
else {
|
|
2252
|
+
(pathItem === null || pathItem === void 0 ? void 0 : pathItem.requestBody) && delete pathItem.requestBody;
|
|
1928
2253
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
2254
|
+
};
|
|
2255
|
+
const getUserShowName = (data) => {
|
|
2256
|
+
if (lodash.isString(data === null || data === void 0 ? void 0 : data.alias_name) && (data === null || data === void 0 ? void 0 : data.alias_name.length) > 0) {
|
|
2257
|
+
return data === null || data === void 0 ? void 0 : data.alias_name;
|
|
1931
2258
|
}
|
|
1932
|
-
|
|
1933
|
-
|
|
2259
|
+
if (lodash.isString(data === null || data === void 0 ? void 0 : data.nick_name) && (data === null || data === void 0 ? void 0 : data.nick_name.length) > 0) {
|
|
2260
|
+
return data === null || data === void 0 ? void 0 : data.nick_name;
|
|
1934
2261
|
}
|
|
1935
|
-
return
|
|
2262
|
+
return '';
|
|
1936
2263
|
};
|
|
1937
|
-
const
|
|
1938
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
}
|
|
1950
|
-
if (pre) {
|
|
1951
|
-
raw_para.push({
|
|
1952
|
-
key: `${pre}`,
|
|
1953
|
-
value: (schema === null || schema === void 0 ? void 0 : schema.example) || (schema === null || schema === void 0 ? void 0 : schema.default) || "",
|
|
1954
|
-
description: String((schema === null || schema === void 0 ? void 0 : schema.description) || ''),
|
|
1955
|
-
not_null: (requiredArr === null || requiredArr === void 0 ? void 0 : requiredArr.find(it => it == propName)) ? 1 : -1,
|
|
1956
|
-
field_type: type ? type.charAt(0).toUpperCase() + type.slice(1) : "String",
|
|
1957
|
-
is_checked: 1,
|
|
1958
|
-
param_id: apipostTools.snowflakeId(),
|
|
1959
|
-
});
|
|
1960
|
-
}
|
|
1961
|
-
return example;
|
|
2264
|
+
const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, target_type) => {
|
|
2265
|
+
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, _12, _13, _14, _15, _16, _17, _18, _19, _20;
|
|
2266
|
+
const path = recursiveFolderPath("", sourceObj, pid, pidName);
|
|
2267
|
+
const pathItem = {
|
|
2268
|
+
'x-target-id': (item === null || item === void 0 ? void 0 : item.target_id) || '',
|
|
2269
|
+
'x-protocol': target_type || '',
|
|
2270
|
+
summary: (item === null || item === void 0 ? void 0 : item.name) || "",
|
|
2271
|
+
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
2272
|
+
tags: []
|
|
2273
|
+
};
|
|
2274
|
+
if (lodash.isArray(item === null || item === void 0 ? void 0 : item.tags) && (item === null || item === void 0 ? void 0 : item.tags.length) > 0) {
|
|
2275
|
+
pathItem['x-tags'] = item === null || item === void 0 ? void 0 : item.tags;
|
|
1962
2276
|
}
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
// raw_para.push({
|
|
1966
|
-
// key: `${pre}`,
|
|
1967
|
-
// value: "",
|
|
1968
|
-
// description: String(schema?.description || ''),
|
|
1969
|
-
// not_null: requiredArr?.find(it => it == propName) ? 1 : -1,
|
|
1970
|
-
// field_type: "Array",
|
|
1971
|
-
// is_checked: 1,
|
|
1972
|
-
// param_id: snowflakeId(),
|
|
1973
|
-
// });
|
|
1974
|
-
let itemsType = ((_d = (_c = (_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.oneOf) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.type) || ((_e = schema === null || schema === void 0 ? void 0 : schema.items) === null || _e === void 0 ? void 0 : _e.type) || 'string';
|
|
1975
|
-
if (itemsType === 'object') {
|
|
1976
|
-
let properties = ((_h = (_g = (_f = schema === null || schema === void 0 ? void 0 : schema.items) === null || _f === void 0 ? void 0 : _f.oneOf) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.properties) || ((_j = schema === null || schema === void 0 ? void 0 : schema.items) === null || _j === void 0 ? void 0 : _j.properties) || ((_k = schema === null || schema === void 0 ? void 0 : schema.additionalProperties) === null || _k === void 0 ? void 0 : _k.properties) || (schema === null || schema === void 0 ? void 0 : schema.properties) || {};
|
|
1977
|
-
let required = ((_o = (_m = (_l = schema === null || schema === void 0 ? void 0 : schema.items) === null || _l === void 0 ? void 0 : _l.oneOf) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.required) || ((_p = schema === null || schema === void 0 ? void 0 : schema.items) === null || _p === void 0 ? void 0 : _p.required) || ((_q = schema === null || schema === void 0 ? void 0 : schema.additionalProperties) === null || _q === void 0 ? void 0 : _q.required) || (schema === null || schema === void 0 ? void 0 : schema.required) || [];
|
|
1978
|
-
let obj = {};
|
|
1979
|
-
for (const key in properties) {
|
|
1980
|
-
if (lodash.has(properties, key)) {
|
|
1981
|
-
const item = properties[key];
|
|
1982
|
-
obj[key] = handleBodyJsonSchema(item, raw_para, pre ? `${pre}.${key}` : `${key}`, required, key);
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
example.push(obj);
|
|
1986
|
-
}
|
|
1987
|
-
else if (itemsType === "integer") {
|
|
1988
|
-
let value = ((_t = (_s = (_r = schema === null || schema === void 0 ? void 0 : schema.items) === null || _r === void 0 ? void 0 : _r.oneOf) === null || _s === void 0 ? void 0 : _s[0]) === null || _t === void 0 ? void 0 : _t.example) || ((_u = schema === null || schema === void 0 ? void 0 : schema.items) === null || _u === void 0 ? void 0 : _u.example) || 0;
|
|
1989
|
-
// console.log(value,"valuevalue");
|
|
1990
|
-
if (Object.prototype.toString.call(raw_para) === '[object Array]') {
|
|
1991
|
-
raw_para.push({
|
|
1992
|
-
key: `${pre}.0`,
|
|
1993
|
-
value: value ? String(value) : '',
|
|
1994
|
-
description: String((schema === null || schema === void 0 ? void 0 : schema.description) || ''),
|
|
1995
|
-
not_null: (requiredArr === null || requiredArr === void 0 ? void 0 : requiredArr.find(it => it == propName)) ? 1 : -1,
|
|
1996
|
-
field_type: type ? type.charAt(0).toUpperCase() + type.slice(1) : "String",
|
|
1997
|
-
type: "String",
|
|
1998
|
-
is_checked: 1,
|
|
1999
|
-
param_id: apipostTools.snowflakeId(),
|
|
2000
|
-
});
|
|
2001
|
-
}
|
|
2002
|
-
example.push(value);
|
|
2003
|
-
}
|
|
2004
|
-
else {
|
|
2005
|
-
let value = ((_x = (_w = (_v = schema === null || schema === void 0 ? void 0 : schema.items) === null || _v === void 0 ? void 0 : _v.oneOf) === null || _w === void 0 ? void 0 : _w[0]) === null || _x === void 0 ? void 0 : _x.example) || ((_y = schema === null || schema === void 0 ? void 0 : schema.items) === null || _y === void 0 ? void 0 : _y.example) || '';
|
|
2006
|
-
if (Object.prototype.toString.call(raw_para) === '[object Array]') {
|
|
2007
|
-
raw_para.push({
|
|
2008
|
-
key: `${pre}.0`,
|
|
2009
|
-
value: value || '',
|
|
2010
|
-
description: String((schema === null || schema === void 0 ? void 0 : schema.description) || ''),
|
|
2011
|
-
not_null: (requiredArr === null || requiredArr === void 0 ? void 0 : requiredArr.find(it => it == propName)) ? 1 : -1,
|
|
2012
|
-
field_type: type ? type.charAt(0).toUpperCase() + type.slice(1) : "String",
|
|
2013
|
-
type: "String",
|
|
2014
|
-
is_checked: 1,
|
|
2015
|
-
param_id: apipostTools.snowflakeId(),
|
|
2016
|
-
});
|
|
2017
|
-
}
|
|
2018
|
-
example.push(value);
|
|
2019
|
-
}
|
|
2020
|
-
return example;
|
|
2277
|
+
if (lodash.isString(item === null || item === void 0 ? void 0 : item.mark_id)) {
|
|
2278
|
+
pathItem['x-mark-id'] = item === null || item === void 0 ? void 0 : item.mark_id;
|
|
2021
2279
|
}
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
raw_para.push({
|
|
2025
|
-
key: `${pre}`,
|
|
2026
|
-
value: ((schema === null || schema === void 0 ? void 0 : schema.example) || (schema === null || schema === void 0 ? void 0 : schema.default)) ? String((schema === null || schema === void 0 ? void 0 : schema.example) || (schema === null || schema === void 0 ? void 0 : schema.default)) : '',
|
|
2027
|
-
description: String((schema === null || schema === void 0 ? void 0 : schema.description) || ''),
|
|
2028
|
-
not_null: (requiredArr === null || requiredArr === void 0 ? void 0 : requiredArr.find(it => it == propName)) ? 1 : -1,
|
|
2029
|
-
field_type: type ? type.charAt(0).toUpperCase() + type.slice(1) : "String",
|
|
2030
|
-
is_checked: 1,
|
|
2031
|
-
param_id: apipostTools.snowflakeId(),
|
|
2032
|
-
});
|
|
2033
|
-
}
|
|
2034
|
-
return (schema === null || schema === void 0 ? void 0 : schema.example) || (schema === null || schema === void 0 ? void 0 : schema.default) || 0;
|
|
2280
|
+
if (lodash.isString(item === null || item === void 0 ? void 0 : item.updated_at)) {
|
|
2281
|
+
pathItem['x-updated-at'] = item === null || item === void 0 ? void 0 : item.updated_at;
|
|
2035
2282
|
}
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2283
|
+
if (lodash.isString((_a = item === null || item === void 0 ? void 0 : item.updated_user) === null || _a === void 0 ? void 0 : _a.nick_name)) {
|
|
2284
|
+
pathItem['x-updated-user-name'] = getUserShowName(item === null || item === void 0 ? void 0 : item.updated_user);
|
|
2285
|
+
}
|
|
2286
|
+
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)) {
|
|
2287
|
+
pathItem['x-attribute-info'] = item === null || item === void 0 ? void 0 : item.attribute_info;
|
|
2288
|
+
}
|
|
2289
|
+
if ((item === null || item === void 0 ? void 0 : item.is_exampled) === 1) {
|
|
2290
|
+
pathItem['x-exampled'] = item === null || item === void 0 ? void 0 : item.is_exampled;
|
|
2291
|
+
}
|
|
2292
|
+
if (['http', 'sse'].includes(target_type)) {
|
|
2293
|
+
// 处理 Query 和 Header 参数
|
|
2294
|
+
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);
|
|
2295
|
+
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);
|
|
2296
|
+
handlePathItemParameters("cookie", ((_g = (_f = item === null || item === void 0 ? void 0 : item.request) === null || _f === void 0 ? void 0 : _f.cookie) === null || _g === void 0 ? void 0 : _g.parameter) || [], pathItem);
|
|
2297
|
+
handlePathItemParameters("path", ((_j = (_h = item === null || item === void 0 ? void 0 : item.request) === null || _h === void 0 ? void 0 : _h.restful) === null || _j === void 0 ? void 0 : _j.parameter) || [], pathItem);
|
|
2298
|
+
// 处理请求体参数(根据 Swagger 版本)
|
|
2299
|
+
if (apiVersion === "2.0") {
|
|
2300
|
+
handlePathItemBodyParameters(((_k = item === null || item === void 0 ? void 0 : item.request) === null || _k === void 0 ? void 0 : _k.body) || {}, pathItem, modelsObj);
|
|
2301
|
+
pathItem.consumes = getSwaggerMode((_m = (_l = item === null || item === void 0 ? void 0 : item.request) === null || _l === void 0 ? void 0 : _l.body) === null || _m === void 0 ? void 0 : _m.mode); // getApipostMode
|
|
2047
2302
|
}
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
for (const key in schemaObj) {
|
|
2055
|
-
const value = schemaObj[key];
|
|
2056
|
-
// 如果当前属性的值是一个对象,则递归遍历该对象
|
|
2057
|
-
if (typeof value === 'object' && value !== null) {
|
|
2058
|
-
// 查找并替换 insAppInfo 对象
|
|
2059
|
-
if (lodash.has(value, 'ref') || lodash.has(value, '$ref')) {
|
|
2060
|
-
let newIuid = apipostTools.snowflakeId();
|
|
2061
|
-
if ((value === null || value === void 0 ? void 0 : value.ref) && value.ref.startsWith('http://localhost:8000/')) {
|
|
2062
|
-
const index = (_a = value.ref) === null || _a === void 0 ? void 0 : _a.indexOf('#');
|
|
2063
|
-
if (index !== -1) {
|
|
2064
|
-
value.ref = value.ref.substring(index);
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
schemaObj[key] = {
|
|
2068
|
-
['x-schema-refs']: {
|
|
2069
|
-
[newIuid]: {
|
|
2070
|
-
$ref: (value === null || value === void 0 ? void 0 : value.ref) || (value === null || value === void 0 ? void 0 : value['$ref'])
|
|
2071
|
-
},
|
|
2072
|
-
},
|
|
2073
|
-
properties: {},
|
|
2074
|
-
['x-schema-orders']: [newIuid],
|
|
2075
|
-
type: "object"
|
|
2076
|
-
};
|
|
2077
|
-
continue;
|
|
2078
|
-
}
|
|
2079
|
-
replaceRef(value);
|
|
2080
|
-
}
|
|
2303
|
+
else {
|
|
2304
|
+
handlePathItemRequestBody(((_o = item === null || item === void 0 ? void 0 : item.request) === null || _o === void 0 ? void 0 : _o.body) || {}, pathItem, modelsObj);
|
|
2305
|
+
}
|
|
2306
|
+
// 添加路径标签
|
|
2307
|
+
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
2308
|
+
pathItem.tags = [...pathItem.tags, path];
|
|
2081
2309
|
}
|
|
2310
|
+
// 处理响应
|
|
2311
|
+
pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
|
|
2082
2312
|
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
jsonSchema.ref = jsonSchema.ref.substring(index);
|
|
2108
|
-
}
|
|
2313
|
+
else if (['websocket2', 'socketio', 'graphql'].includes(target_type)) {
|
|
2314
|
+
// 拼接description
|
|
2315
|
+
if (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.config)) {
|
|
2316
|
+
switch (target_type) {
|
|
2317
|
+
case 'socketio':
|
|
2318
|
+
pathItem.description = `${pathItem.description}
|
|
2319
|
+
${((_p = item === null || item === void 0 ? void 0 : item.config) === null || _p === void 0 ? void 0 : _p.shake_hands_path) ? t('securityConnectionMessage', {
|
|
2320
|
+
enable: ((_q = item === null || item === void 0 ? void 0 : item.config) === null || _q === void 0 ? void 0 : _q.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
|
|
2321
|
+
version: ((_r = item === null || item === void 0 ? void 0 : item.config) === null || _r === void 0 ? void 0 : _r.socket_version) || 'v4',
|
|
2322
|
+
path: (_s = item === null || item === void 0 ? void 0 : item.config) === null || _s === void 0 ? void 0 : _s.shake_hands_path
|
|
2323
|
+
}) : t('securityConnectionMessageNoPath', {
|
|
2324
|
+
enable: ((_t = item === null || item === void 0 ? void 0 : item.config) === null || _t === void 0 ? void 0 : _t.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
|
|
2325
|
+
version: ((_u = item === null || item === void 0 ? void 0 : item.config) === null || _u === void 0 ? void 0 : _u.socket_version) || 'v4',
|
|
2326
|
+
})}
|
|
2327
|
+
`;
|
|
2328
|
+
break;
|
|
2329
|
+
case 'websocket2':
|
|
2330
|
+
pathItem.description = `${pathItem.description}
|
|
2331
|
+
${t('wsConfigMessage', {
|
|
2332
|
+
enable: ((_v = item === null || item === void 0 ? void 0 : item.config) === null || _v === void 0 ? void 0 : _v.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
|
|
2333
|
+
content: !((_w = item === null || item === void 0 ? void 0 : item.config) === null || _w === void 0 ? void 0 : _w.information_size) || ((_x = item === null || item === void 0 ? void 0 : item.config) === null || _x === void 0 ? void 0 : _x.information_size) == 0 ? t('unlimited') : `${(_y = item === null || item === void 0 ? void 0 : item.config) === null || _y === void 0 ? void 0 : _y.information_size}M`
|
|
2334
|
+
})}
|
|
2335
|
+
`;
|
|
2336
|
+
break;
|
|
2109
2337
|
}
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
};
|
|
2338
|
+
}
|
|
2339
|
+
handlePathItemParameters("query", ((_0 = (_z = item === null || item === void 0 ? void 0 : item.request) === null || _z === void 0 ? void 0 : _z.query) === null || _0 === void 0 ? void 0 : _0.parameter) || [], pathItem);
|
|
2340
|
+
handlePathItemParameters("header", ((_2 = (_1 = item === null || item === void 0 ? void 0 : item.request) === null || _1 === void 0 ? void 0 : _1.header) === null || _2 === void 0 ? void 0 : _2.parameter) || [], pathItem);
|
|
2341
|
+
handlePathItemParameters("cookie", ((_4 = (_3 = item === null || item === void 0 ? void 0 : item.request) === null || _3 === void 0 ? void 0 : _3.cookie) === null || _4 === void 0 ? void 0 : _4.parameter) || [], pathItem);
|
|
2342
|
+
handlePathItemParameters("path", ((_6 = (_5 = item === null || item === void 0 ? void 0 : item.request) === null || _5 === void 0 ? void 0 : _5.restful) === null || _6 === void 0 ? void 0 : _6.parameter) || [], pathItem);
|
|
2343
|
+
if (target_type == 'socketio')
|
|
2344
|
+
handlePathItemParameters("event", ((_8 = (_7 = item === null || item === void 0 ? void 0 : item.request) === null || _7 === void 0 ? void 0 : _7.event) === null || _8 === void 0 ? void 0 : _8.parameter) || [], pathItem);
|
|
2345
|
+
// 处理请体
|
|
2346
|
+
if (target_type == 'graphql') {
|
|
2347
|
+
handleGraphqlRequestBody(((_10 = (_9 = item === null || item === void 0 ? void 0 : item.request) === null || _9 === void 0 ? void 0 : _9.body) === null || _10 === void 0 ? void 0 : _10.query_list) || [], ((_12 = (_11 = item === null || item === void 0 ? void 0 : item.request) === null || _11 === void 0 ? void 0 : _11.body) === null || _12 === void 0 ? void 0 : _12.query_schema) || {}, pathItem, modelsObj);
|
|
2120
2348
|
}
|
|
2121
2349
|
else {
|
|
2122
|
-
|
|
2350
|
+
handleMessagePathItemrequestBody((item === null || item === void 0 ? void 0 : item.message) || [], pathItem, modelsObj);
|
|
2351
|
+
}
|
|
2352
|
+
// 添加路径标签
|
|
2353
|
+
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
2354
|
+
pathItem.tags = [...pathItem.tags, path];
|
|
2123
2355
|
}
|
|
2124
2356
|
}
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2357
|
+
else if (target_type == 'socket_method') {
|
|
2358
|
+
// 拼接description
|
|
2359
|
+
const configs = (_13 = item === null || item === void 0 ? void 0 : item.request) === null || _13 === void 0 ? void 0 : _13.configs;
|
|
2360
|
+
if (lodash.isPlainObject(configs)) {
|
|
2361
|
+
let requestString = `${t('requestEncodingFormat', { format: configs === null || configs === void 0 ? void 0 : configs.charset })} ${lodash.isArray((_14 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _14 === void 0 ? void 0 : _14.request) && ((_15 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _15 === void 0 ? void 0 : _15.request.length) > 0 ?
|
|
2362
|
+
`\n${t('needAddRequestDataHandleFunction')}\n${(_16 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _16 === void 0 ? void 0 : _16.request.map((r, index) => {
|
|
2363
|
+
let str = getTcpMethodFucString(r);
|
|
2364
|
+
return str;
|
|
2365
|
+
})}`
|
|
2366
|
+
: ''}`;
|
|
2367
|
+
let responseString = lodash.isArray((_17 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _17 === void 0 ? void 0 : _17.response) && ((_18 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _18 === void 0 ? void 0 : _18.response.length) > 0 ?
|
|
2368
|
+
`${t('needAddResponseDataHandleFunction')}\n${(_19 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _19 === void 0 ? void 0 : _19.response.map((r, index) => {
|
|
2369
|
+
let str = getTcpMethodFucString(r);
|
|
2370
|
+
return str;
|
|
2371
|
+
})}`
|
|
2372
|
+
: '';
|
|
2373
|
+
pathItem.description = `${pathItem.description}\n${requestString}\n${responseString}`;
|
|
2374
|
+
}
|
|
2375
|
+
handleSocketMethodRequestBody(((_20 = item === null || item === void 0 ? void 0 : item.request) === null || _20 === void 0 ? void 0 : _20.body) || {}, pathItem);
|
|
2376
|
+
// 处理响应
|
|
2377
|
+
pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
|
|
2378
|
+
// 添加路径标签
|
|
2379
|
+
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
2380
|
+
pathItem.tags = [...pathItem.tags, path];
|
|
2381
|
+
}
|
|
2143
2382
|
}
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
'model_id': '',
|
|
2150
|
-
'name': folder_name || 'New Folder',
|
|
2151
|
-
'model_type': 'folder',
|
|
2152
|
-
'description': folder_name || '',
|
|
2153
|
-
'children': [],
|
|
2154
|
-
};
|
|
2155
|
-
return newFolder;
|
|
2156
|
-
};
|
|
2157
|
-
const createNewModelData = (item, key, folder_name) => {
|
|
2158
|
-
var model = {
|
|
2159
|
-
model_id: `#/components/${folder_name}/${key}`,
|
|
2160
|
-
name: key || (item === null || item === void 0 ? void 0 : item.title) || key || 'New Schema',
|
|
2161
|
-
// displayName:key || item?.title || '',
|
|
2162
|
-
// display_name:key || item?.title || '',
|
|
2163
|
-
model_type: 'model',
|
|
2164
|
-
description: (item === null || item === void 0 ? void 0 : item.description) || '',
|
|
2165
|
-
schema: {},
|
|
2166
|
-
};
|
|
2167
|
-
try {
|
|
2168
|
-
model.schema = swaggerSchema2apipostSchema(item);
|
|
2383
|
+
else if (target_type == 'doc') {
|
|
2384
|
+
// 添加路径标签
|
|
2385
|
+
if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
|
|
2386
|
+
pathItem.tags = [...pathItem.tags, path];
|
|
2387
|
+
}
|
|
2169
2388
|
}
|
|
2170
|
-
|
|
2171
|
-
return model;
|
|
2172
|
-
};
|
|
2173
|
-
const endsWith = (str, suffix) => {
|
|
2174
|
-
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
2175
|
-
};
|
|
2176
|
-
const transFieldType = (str) => {
|
|
2177
|
-
var _a;
|
|
2178
|
-
if (!str)
|
|
2179
|
-
return 'String';
|
|
2180
|
-
return ((_a = str === null || str === void 0 ? void 0 : str.charAt(0)) === null || _a === void 0 ? void 0 : _a.toUpperCase()) + (str === null || str === void 0 ? void 0 : str.slice(1));
|
|
2389
|
+
return pathItem;
|
|
2181
2390
|
};
|
|
2182
|
-
const
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2391
|
+
const getTcpMethodFucString = (func) => {
|
|
2392
|
+
switch (func === null || func === void 0 ? void 0 : func.id) {
|
|
2393
|
+
case 'addCharToPacketEnd':
|
|
2394
|
+
return t('addNewline', { str: func === null || func === void 0 ? void 0 : func.option });
|
|
2395
|
+
case 'calcLengthToPacketHeader':
|
|
2396
|
+
return t('addContentLength', { size: func === null || func === void 0 ? void 0 : func.option });
|
|
2397
|
+
case 'removePacketHeader':
|
|
2398
|
+
return t('removeResponseHeader', { size: func === null || func === void 0 ? void 0 : func.option });
|
|
2399
|
+
case 'removeWrapChar':
|
|
2400
|
+
return t('trimTrailingNewline', { str: func === null || func === void 0 ? void 0 : func.option });
|
|
2401
|
+
case 'parseXmlToJson':
|
|
2402
|
+
return t('convertXmlToJson');
|
|
2187
2403
|
}
|
|
2188
|
-
return '
|
|
2404
|
+
return '';
|
|
2189
2405
|
};
|
|
2190
|
-
const
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2406
|
+
const getSocketRequestStr = (end_func) => {
|
|
2407
|
+
switch (end_func === null || end_func === void 0 ? void 0 : end_func.name) {
|
|
2408
|
+
case 'none':
|
|
2409
|
+
return t('completeOnReceive');
|
|
2410
|
+
case 'endedChar':
|
|
2411
|
+
return t('specialCharText', { str: end_func === null || end_func === void 0 ? void 0 : end_func.option });
|
|
2412
|
+
case 'endedHexChar':
|
|
2413
|
+
return t('specialCharBinary', { str: end_func === null || end_func === void 0 ? void 0 : end_func.option });
|
|
2414
|
+
case 'endedHeaderByteLength':
|
|
2415
|
+
return t('headerBodyFormat', { size: end_func === null || end_func === void 0 ? void 0 : end_func.option });
|
|
2416
|
+
case 'endedContentByteLength':
|
|
2417
|
+
return t('fixedLength', { size: end_func === null || end_func === void 0 ? void 0 : end_func.option });
|
|
2199
2418
|
}
|
|
2419
|
+
return '';
|
|
2200
2420
|
};
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
param_id: apipostTools.snowflakeId(),
|
|
2216
|
-
schema: (p === null || p === void 0 ? void 0 : p.schema) || {}
|
|
2217
|
-
};
|
|
2421
|
+
|
|
2422
|
+
class ApipostToSwagger {
|
|
2423
|
+
constructor() {
|
|
2424
|
+
Object.defineProperty(this, "apiToSwaggerOrigin", {
|
|
2425
|
+
enumerable: true,
|
|
2426
|
+
configurable: true,
|
|
2427
|
+
writable: true,
|
|
2428
|
+
value: void 0
|
|
2429
|
+
});
|
|
2430
|
+
Object.defineProperty(this, "apiToSwaggerResult", {
|
|
2431
|
+
enumerable: true,
|
|
2432
|
+
configurable: true,
|
|
2433
|
+
writable: true,
|
|
2434
|
+
value: void 0
|
|
2218
2435
|
});
|
|
2436
|
+
Object.defineProperty(this, "apiToSwaggerVersion", {
|
|
2437
|
+
enumerable: true,
|
|
2438
|
+
configurable: true,
|
|
2439
|
+
writable: true,
|
|
2440
|
+
value: void 0
|
|
2441
|
+
});
|
|
2442
|
+
this.apiToSwaggerOrigin = {};
|
|
2443
|
+
this.apiToSwaggerResult = {};
|
|
2444
|
+
this.apiToSwaggerVersion = "2.0";
|
|
2219
2445
|
}
|
|
2220
|
-
|
|
2221
|
-
};
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
key: key || "",
|
|
2227
|
-
value: transExample(value === null || value === void 0 ? void 0 : value.example) || "",
|
|
2228
|
-
not_null: (value === null || value === void 0 ? void 0 : value.required) ? 1 : -1,
|
|
2229
|
-
description: anyToString(value === null || value === void 0 ? void 0 : value.description) || "",
|
|
2230
|
-
field_type: lodash.has(value, "type")
|
|
2231
|
-
? value.type.charAt(0).toUpperCase() + value.type.slice(1)
|
|
2232
|
-
: "String",
|
|
2233
|
-
param_id: apipostTools.snowflakeId(),
|
|
2234
|
-
schema: (value === null || value === void 0 ? void 0 : value.schema) || {}
|
|
2446
|
+
handleProject() {
|
|
2447
|
+
const { name, intro, marks, attributes } = this.apiToSwaggerOrigin.project || {};
|
|
2448
|
+
this.apiToSwaggerResult.info = {
|
|
2449
|
+
title: name || t('createProj'),
|
|
2450
|
+
description: intro || "",
|
|
2451
|
+
version: "1.0.0",
|
|
2235
2452
|
};
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
const getBeautifulRaw = (raw) => {
|
|
2239
|
-
var _a;
|
|
2240
|
-
try {
|
|
2241
|
-
if (!raw) {
|
|
2242
|
-
return raw;
|
|
2453
|
+
if (this.apiToSwaggerVersion == "2.0") {
|
|
2454
|
+
this.apiToSwaggerResult.swagger = "2.0";
|
|
2243
2455
|
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
catch (err) {
|
|
2247
|
-
return raw;
|
|
2248
|
-
}
|
|
2249
|
-
};
|
|
2250
|
-
const completionBodyRaw = (bodyData) => {
|
|
2251
|
-
let raw = '';
|
|
2252
|
-
if (lodash.has(bodyData, "example")) {
|
|
2253
|
-
let example = bodyData.example;
|
|
2254
|
-
if (typeof example == "object") {
|
|
2255
|
-
example = JSON.stringify(example);
|
|
2456
|
+
else if (this.apiToSwaggerVersion == "3.0") {
|
|
2457
|
+
this.apiToSwaggerResult.openapi = "3.0.0";
|
|
2256
2458
|
}
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
if (lodash.has(bodyData, "schema")) {
|
|
2260
|
-
const raw_parameter = [];
|
|
2261
|
-
const Raw = handleBodyJsonSchema(bodyData.schema, raw_parameter);
|
|
2262
|
-
const Raw_text = lodash.isPlainObject(Raw) || Array.isArray(Raw)
|
|
2263
|
-
? JSON.stringify(Raw)
|
|
2264
|
-
: Raw;
|
|
2265
|
-
raw = raw ? raw : Raw_text;
|
|
2266
|
-
// if (isEmpty(raw)) {
|
|
2267
|
-
// try {
|
|
2268
|
-
// const myMockSchema = new (MockSchema as any)();
|
|
2269
|
-
// const schemaJson = await myMockSchema.mock(bodyData.schema);
|
|
2270
|
-
// raw =
|
|
2271
|
-
// isPlainObject(schemaJson) || Array.isArray(Raw)
|
|
2272
|
-
// ? JSON.stringify(schemaJson)
|
|
2273
|
-
// : schemaJson;
|
|
2274
|
-
// } catch (error) { }
|
|
2275
|
-
// }
|
|
2276
|
-
}
|
|
2277
|
-
if (!lodash.isString(raw)) {
|
|
2278
|
-
raw = JSON.stringify(raw);
|
|
2279
|
-
}
|
|
2280
|
-
return getBeautifulRaw(raw);
|
|
2281
|
-
};
|
|
2282
|
-
const completionBodyRawParameter = (bodyData) => {
|
|
2283
|
-
const raw_parameter = [];
|
|
2284
|
-
handleBodyJsonSchema(bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema, raw_parameter);
|
|
2285
|
-
return raw_parameter;
|
|
2286
|
-
};
|
|
2287
|
-
const completionBody = (swaggerApi) => {
|
|
2288
|
-
var _a, _b;
|
|
2289
|
-
const content = ((_a = swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.requestBody) === null || _a === void 0 ? void 0 : _a.content) || {};
|
|
2290
|
-
const mode = lodash.isPlainObject(content) && !lodash.isEmpty(content) ? Object.keys(content)[0] : "none";
|
|
2291
|
-
const bodyData = (content === null || content === void 0 ? void 0 : content[mode]) || {};
|
|
2292
|
-
const apipostMode = getApipostMode(mode);
|
|
2293
|
-
let properties = {};
|
|
2294
|
-
if (lodash.has(bodyData, "schema")) {
|
|
2295
|
-
const { schema } = bodyData;
|
|
2296
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.type) === "array") {
|
|
2297
|
-
properties = (_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.properties;
|
|
2459
|
+
if (lodash.isArray(marks) && marks.length > 0) {
|
|
2460
|
+
this.apiToSwaggerResult.info['x-marks'] = marks;
|
|
2298
2461
|
}
|
|
2299
|
-
|
|
2300
|
-
|
|
2462
|
+
if (lodash.isArray(attributes) && attributes.length > 0) {
|
|
2463
|
+
this.apiToSwaggerResult.info['x-attributes'] = attributes;
|
|
2301
2464
|
}
|
|
2302
2465
|
}
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
}
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
},
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'path' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
2323
|
-
},
|
|
2324
|
-
cookie: {
|
|
2325
|
-
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'cookie' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
2326
|
-
},
|
|
2327
|
-
body: Object.assign({}, completionBody(swaggerApi)),
|
|
2328
|
-
};
|
|
2329
|
-
};
|
|
2330
|
-
const completionResponse = (responses) => {
|
|
2331
|
-
const example = [];
|
|
2332
|
-
if (lodash.isPlainObject(responses)) {
|
|
2333
|
-
Object.keys(responses).forEach((status) => {
|
|
2334
|
-
var _a, _b, _c, _d;
|
|
2335
|
-
const element = responses[status];
|
|
2336
|
-
if ((lodash.has(element, "schema") &&
|
|
2337
|
-
lodash.has(element.schema, "properties") &&
|
|
2338
|
-
JSON.stringify(element.schema.properties) !== "{}") ||
|
|
2339
|
-
((_a = element === null || element === void 0 ? void 0 : element.schema) === null || _a === void 0 ? void 0 : _a.type) === "array") {
|
|
2340
|
-
const raw_parameter = [];
|
|
2341
|
-
const Raw = handleBodyJsonSchema(element.schema, raw_parameter);
|
|
2342
|
-
const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
|
|
2343
|
-
? JSON.stringify(Raw)
|
|
2344
|
-
: String(Raw);
|
|
2345
|
-
const Raw_text = getBeautifulRaw(originRaw);
|
|
2346
|
-
let jsonSchema = {};
|
|
2347
|
-
if (Object.prototype.toString.call((_b = element === null || element === void 0 ? void 0 : element.schema) === null || _b === void 0 ? void 0 : _b["$$ref"]) ===
|
|
2348
|
-
"[object String]") {
|
|
2349
|
-
jsonSchema = swaggerSchema2apipostSchema(element.schema);
|
|
2350
|
-
}
|
|
2351
|
-
else {
|
|
2352
|
-
jsonSchema = element.schema;
|
|
2353
|
-
}
|
|
2354
|
-
// 成功响应示例
|
|
2355
|
-
if (String(status) == '200') {
|
|
2356
|
-
example.push({
|
|
2357
|
-
example_id: "1",
|
|
2358
|
-
raw: Raw_text,
|
|
2359
|
-
raw_parameter: raw_parameter,
|
|
2360
|
-
expect: {
|
|
2361
|
-
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
2362
|
-
code: getSubstring(status, 128),
|
|
2363
|
-
content_type: "json",
|
|
2364
|
-
is_default: 1,
|
|
2365
|
-
mock: "",
|
|
2366
|
-
schema: jsonSchema,
|
|
2367
|
-
verify_type: "schema",
|
|
2368
|
-
},
|
|
2369
|
-
});
|
|
2370
|
-
}
|
|
2371
|
-
else if (String(status) == '404') {
|
|
2372
|
-
example.push({
|
|
2373
|
-
example_id: "2",
|
|
2374
|
-
raw: Raw_text,
|
|
2375
|
-
raw_parameter: raw_parameter,
|
|
2376
|
-
expect: {
|
|
2377
|
-
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
2378
|
-
code: getSubstring(status, 128),
|
|
2379
|
-
content_type: "json",
|
|
2380
|
-
is_default: -1,
|
|
2381
|
-
mock: "",
|
|
2382
|
-
schema: jsonSchema,
|
|
2383
|
-
verify_type: "schema",
|
|
2384
|
-
},
|
|
2385
|
-
});
|
|
2466
|
+
handleModels() {
|
|
2467
|
+
var _a, _b;
|
|
2468
|
+
const version = this.apiToSwaggerVersion;
|
|
2469
|
+
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");
|
|
2470
|
+
// 声明一个schema映射表
|
|
2471
|
+
const schemaMap = childModels === null || childModels === void 0 ? void 0 : childModels.reduce((pre, item) => {
|
|
2472
|
+
if ((item === null || item === void 0 ? void 0 : item.model_id) && (item === null || item === void 0 ? void 0 : item.name)) {
|
|
2473
|
+
pre[item === null || item === void 0 ? void 0 : item.model_id] = {
|
|
2474
|
+
schema: (item === null || item === void 0 ? void 0 : item.schema) || { type: 'object', properties: {} },
|
|
2475
|
+
path: schemaPath(item === null || item === void 0 ? void 0 : item.name, version),
|
|
2476
|
+
name: (item === null || item === void 0 ? void 0 : item.name) || '',
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
return pre;
|
|
2480
|
+
}, {});
|
|
2481
|
+
if (lodash.isArray(childModels) && childModels.length > 0) {
|
|
2482
|
+
const schemas = (_b = lodash.values(schemaMap)) === null || _b === void 0 ? void 0 : _b.reduce((pre, item) => {
|
|
2483
|
+
if ((item === null || item === void 0 ? void 0 : item.name) && (item === null || item === void 0 ? void 0 : item.schema)) {
|
|
2484
|
+
pre[item === null || item === void 0 ? void 0 : item.name] = deepModelRef(item === null || item === void 0 ? void 0 : item.schema, schemaMap);
|
|
2386
2485
|
}
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2486
|
+
return pre;
|
|
2487
|
+
}, {});
|
|
2488
|
+
// 先不区分目录概念 把所有的schema都放在schemas目录下 后期加上schemas生成多目录
|
|
2489
|
+
if (version === '2.0') {
|
|
2490
|
+
this.apiToSwaggerResult.definitions = schemas;
|
|
2491
|
+
}
|
|
2492
|
+
if (lodash.isEqual(version, '3.0') || lodash.isEqual(version, '3.0.0')) {
|
|
2493
|
+
this.apiToSwaggerResult.components = { schemas };
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
return schemaMap;
|
|
2497
|
+
}
|
|
2498
|
+
handleEnvs() {
|
|
2499
|
+
const envs = this.apiToSwaggerOrigin.envs;
|
|
2500
|
+
this.apiToSwaggerResult.servers = [];
|
|
2501
|
+
if (lodash.isArray(envs) && envs.length > 0) {
|
|
2502
|
+
for (const env of envs) {
|
|
2503
|
+
const servers = {
|
|
2504
|
+
url: (env === null || env === void 0 ? void 0 : env.url) || "",
|
|
2505
|
+
description: (env === null || env === void 0 ? void 0 : env.name) || t('createEnv'),
|
|
2506
|
+
};
|
|
2507
|
+
if (lodash.isPlainObject(env === null || env === void 0 ? void 0 : env.env_var_list)) {
|
|
2508
|
+
servers.variables = {};
|
|
2509
|
+
for (const key in env === null || env === void 0 ? void 0 : env.env_var_list) {
|
|
2510
|
+
const variable = env.env_var_list[key];
|
|
2511
|
+
servers.variables[key] = {
|
|
2512
|
+
default: (variable === null || variable === void 0 ? void 0 : variable.current_value) || (variable === null || variable === void 0 ? void 0 : variable.value),
|
|
2513
|
+
description: (variable === null || variable === void 0 ? void 0 : variable.description) || "",
|
|
2514
|
+
};
|
|
2515
|
+
}
|
|
2404
2516
|
}
|
|
2517
|
+
this.apiToSwaggerResult.servers.push(servers);
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
formatRequestItem(item) {
|
|
2522
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2523
|
+
const content = ((_a = item === null || item === void 0 ? void 0 : item.requestBody) === null || _a === void 0 ? void 0 : _a.content) || {};
|
|
2524
|
+
const tags = (item === null || item === void 0 ? void 0 : item.tags) || [];
|
|
2525
|
+
const keys = Object.keys(content);
|
|
2526
|
+
if (keys.length > 0) {
|
|
2527
|
+
const key = keys[0];
|
|
2528
|
+
switch (key) {
|
|
2529
|
+
case "multipart/form-data":
|
|
2530
|
+
content[key].schema = {
|
|
2531
|
+
properties: ((_b = content[key]) === null || _b === void 0 ? void 0 : _b.properties) || {},
|
|
2532
|
+
};
|
|
2533
|
+
(_d = (_c = item === null || item === void 0 ? void 0 : item.requestBody) === null || _c === void 0 ? void 0 : _c.content[key]) === null || _d === void 0 ? true : delete _d.properties;
|
|
2534
|
+
item.requestBody.content = content || {};
|
|
2535
|
+
break;
|
|
2536
|
+
case "application/x-www-form-urlencoded":
|
|
2537
|
+
content[key].schema = {
|
|
2538
|
+
properties: ((_e = content[key]) === null || _e === void 0 ? void 0 : _e.properties) || {},
|
|
2539
|
+
};
|
|
2540
|
+
(_g = (_f = item === null || item === void 0 ? void 0 : item.requestBody) === null || _f === void 0 ? void 0 : _f.content[key]) === null || _g === void 0 ? true : delete _g.properties;
|
|
2541
|
+
item.requestBody.content = content || {};
|
|
2542
|
+
break;
|
|
2543
|
+
case "application/json":
|
|
2544
|
+
const exampleStr = (_h = content[key]) === null || _h === void 0 ? void 0 : _h.example;
|
|
2545
|
+
(_k = (_j = item === null || item === void 0 ? void 0 : item.requestBody) === null || _j === void 0 ? void 0 : _j.content[key]) === null || _k === void 0 ? true : delete _k.example;
|
|
2546
|
+
const properties = generateProperties(exampleStr);
|
|
2547
|
+
content[key].schema = {
|
|
2548
|
+
type: "object",
|
|
2549
|
+
properties: properties || {},
|
|
2550
|
+
};
|
|
2551
|
+
break;
|
|
2405
2552
|
}
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2553
|
+
}
|
|
2554
|
+
return Object.assign(Object.assign({}, item), { tags: formatTags(tags[0]) });
|
|
2555
|
+
}
|
|
2556
|
+
formatData() {
|
|
2557
|
+
const paths = this.apiToSwaggerResult.paths;
|
|
2558
|
+
const tempPaths = {};
|
|
2559
|
+
for (const path in paths) {
|
|
2560
|
+
const item = paths[path];
|
|
2561
|
+
const keys = Object.keys(item);
|
|
2562
|
+
if (keys.length > 0) {
|
|
2563
|
+
const key = keys[0];
|
|
2564
|
+
const tempData = this.formatRequestItem(lodash.cloneDeep(item[key]));
|
|
2565
|
+
tempPaths[path] = {
|
|
2566
|
+
[key.toLocaleLowerCase()]: tempData,
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
this.apiToSwaggerResult.paths = tempPaths;
|
|
2571
|
+
}
|
|
2572
|
+
array2NamePathObj(idName = "id", pidName = "pid", modelsObj) {
|
|
2573
|
+
var _a, _b, _c, _d, _e;
|
|
2574
|
+
const items = lodash.cloneDeep(this.apiToSwaggerOrigin.apis);
|
|
2575
|
+
try {
|
|
2576
|
+
const paths = {};
|
|
2577
|
+
const folderObj = {};
|
|
2578
|
+
const sourceObj = {};
|
|
2579
|
+
items.forEach((item) => {
|
|
2580
|
+
sourceObj[item[idName]] = item;
|
|
2581
|
+
});
|
|
2582
|
+
for (const item of items) {
|
|
2583
|
+
const id = item[idName];
|
|
2584
|
+
const pid = item[pidName];
|
|
2585
|
+
if (!id || id == undefined) {
|
|
2586
|
+
continue;
|
|
2417
2587
|
}
|
|
2418
|
-
if (
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2588
|
+
if (['sse', 'api'].includes(item.target_type)) {
|
|
2589
|
+
const temp_url = removeQuery(item === null || item === void 0 ? void 0 : item.url);
|
|
2590
|
+
const targetMethod = (_a = item === null || item === void 0 ? void 0 : item.method) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
2591
|
+
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type == 'api' ? 'http' : item.target_type);
|
|
2592
|
+
if (!paths[temp_url])
|
|
2593
|
+
paths[temp_url] = {};
|
|
2594
|
+
if (!paths[temp_url][targetMethod]) {
|
|
2595
|
+
paths[temp_url][targetMethod] = pathItem;
|
|
2425
2596
|
}
|
|
2426
|
-
if (
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
if (Object.prototype.toString.call(example) ===
|
|
2432
|
-
"[object Object]") {
|
|
2433
|
-
originRaw = JSON.stringify(Object.assign({}, example));
|
|
2434
|
-
}
|
|
2435
|
-
else {
|
|
2436
|
-
originRaw = String(example);
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2439
|
-
catch (error) {
|
|
2440
|
-
originRaw = String(example);
|
|
2597
|
+
else if (pathItem.tags.length > 0) {
|
|
2598
|
+
lodash.forEach(pathItem.tags, tag => {
|
|
2599
|
+
if (!paths[temp_url][targetMethod].tags.includes(tag)) {
|
|
2600
|
+
// 排除重复目录
|
|
2601
|
+
paths[temp_url][targetMethod].tags.push(tag);
|
|
2441
2602
|
}
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
is_default: status == 200 ? 1 : -1,
|
|
2452
|
-
mock: "",
|
|
2453
|
-
schema: jsonSchema,
|
|
2454
|
-
verify_type: "schema",
|
|
2455
|
-
},
|
|
2456
|
-
});
|
|
2603
|
+
});
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
else if (["folder", "socket"].includes(item.target_type)) {
|
|
2607
|
+
const path = recursiveFolderPath(`${item === null || item === void 0 ? void 0 : item.name}`, sourceObj, pid, pidName);
|
|
2608
|
+
item.path = path;
|
|
2609
|
+
if (!lodash.has(folderObj, item === null || item === void 0 ? void 0 : item.name)) {
|
|
2610
|
+
if (!this.apiToSwaggerResult.tags) {
|
|
2611
|
+
this.apiToSwaggerResult.tags = [];
|
|
2457
2612
|
}
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
}
|
|
2467
|
-
else {
|
|
2468
|
-
originRaw = example;
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
|
-
catch (error) {
|
|
2472
|
-
originRaw = String(example);
|
|
2613
|
+
// 收到数据即认为完成(不处理分包问题) none
|
|
2614
|
+
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)) {
|
|
2615
|
+
if (!(folderObj === null || folderObj === void 0 ? void 0 : folderObj[item === null || item === void 0 ? void 0 : item.name])) {
|
|
2616
|
+
item.description = `| ${t('serverAddress')} | ${t('pktCompletion')} |
|
|
2617
|
+
| --- | --- |
|
|
2618
|
+
| ${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)}
|
|
2619
|
+
${item.description}
|
|
2620
|
+
`;
|
|
2473
2621
|
}
|
|
2474
|
-
const Raw_text = getBeautifulRaw(originRaw);
|
|
2475
|
-
example.push({
|
|
2476
|
-
example_id: newUUID,
|
|
2477
|
-
raw: Raw_text,
|
|
2478
|
-
raw_parameter: [],
|
|
2479
|
-
expect: {
|
|
2480
|
-
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
2481
|
-
code: getSubstring(status, 128),
|
|
2482
|
-
content_type: "json",
|
|
2483
|
-
is_default: -1,
|
|
2484
|
-
mock: "",
|
|
2485
|
-
schema: jsonSchema,
|
|
2486
|
-
verify_type: "schema",
|
|
2487
|
-
},
|
|
2488
|
-
});
|
|
2489
2622
|
}
|
|
2623
|
+
this.apiToSwaggerResult.tags.push({
|
|
2624
|
+
name: (item === null || item === void 0 ? void 0 : item.name) || t('createDir'),
|
|
2625
|
+
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
2626
|
+
'x-type': item.target_type,
|
|
2627
|
+
'x-url': (item === null || item === void 0 ? void 0 : item.url) || '',
|
|
2628
|
+
'x-target-id': (item === null || item === void 0 ? void 0 : item.target_id) || ''
|
|
2629
|
+
});
|
|
2630
|
+
folderObj[item === null || item === void 0 ? void 0 : item.name] = item;
|
|
2490
2631
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
code: getSubstring(status, 128),
|
|
2507
|
-
content_type: "json",
|
|
2508
|
-
is_default: status == 200 ? 1 : -1,
|
|
2509
|
-
mock: "",
|
|
2510
|
-
schema: jsonSchema,
|
|
2511
|
-
verify_type: "schema",
|
|
2512
|
-
},
|
|
2513
|
-
});
|
|
2632
|
+
}
|
|
2633
|
+
else if (['websocket2', 'socketio', 'graphql'].includes(item.target_type)) {
|
|
2634
|
+
const temp_url = removeQuery(item === null || item === void 0 ? void 0 : item.url);
|
|
2635
|
+
const targetMethod = `x-${item === null || item === void 0 ? void 0 : item.target_id}`;
|
|
2636
|
+
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
|
|
2637
|
+
if (!paths[temp_url])
|
|
2638
|
+
paths[temp_url] = {};
|
|
2639
|
+
if (!paths[temp_url][targetMethod]) {
|
|
2640
|
+
paths[temp_url][targetMethod] = pathItem;
|
|
2641
|
+
}
|
|
2642
|
+
else if (pathItem.tags.length > 0) {
|
|
2643
|
+
lodash.forEach(pathItem.tags, tag => {
|
|
2644
|
+
if (!paths[temp_url][targetMethod].tags.includes(tag)) {
|
|
2645
|
+
// 排除重复目录
|
|
2646
|
+
paths[temp_url][targetMethod].tags.push(tag);
|
|
2514
2647
|
}
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2648
|
+
});
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
else if (item.target_type === 'socket_method') {
|
|
2652
|
+
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}`;
|
|
2653
|
+
const targetMethod = `x-${item.target_id}`;
|
|
2654
|
+
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
|
|
2655
|
+
if (!paths[temp_url])
|
|
2656
|
+
paths[temp_url] = {};
|
|
2657
|
+
if (!paths[temp_url][targetMethod]) {
|
|
2658
|
+
paths[temp_url][targetMethod] = pathItem;
|
|
2659
|
+
}
|
|
2660
|
+
else if (pathItem.tags.length > 0) {
|
|
2661
|
+
lodash.forEach(pathItem.tags, tag => {
|
|
2662
|
+
if (!paths[temp_url][targetMethod].tags.includes(tag)) {
|
|
2663
|
+
// 排除重复目录
|
|
2664
|
+
paths[temp_url][targetMethod].tags.push(tag);
|
|
2665
|
+
}
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
else if (item.target_type === 'doc') {
|
|
2670
|
+
const temp_url = `x-${item.target_id}`;
|
|
2671
|
+
const targetMethod = `x-${item === null || item === void 0 ? void 0 : item.name}`;
|
|
2672
|
+
const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
|
|
2673
|
+
if (!paths[temp_url])
|
|
2674
|
+
paths[temp_url] = {};
|
|
2675
|
+
if (!paths[temp_url][targetMethod]) {
|
|
2676
|
+
paths[temp_url][targetMethod] = pathItem;
|
|
2677
|
+
}
|
|
2678
|
+
else if (pathItem.tags.length > 0) {
|
|
2679
|
+
lodash.forEach(pathItem.tags, tag => {
|
|
2680
|
+
if (!paths[temp_url][targetMethod].tags.includes(tag)) {
|
|
2681
|
+
// 排除重复目录
|
|
2682
|
+
paths[temp_url][targetMethod].tags.push(tag);
|
|
2532
2683
|
}
|
|
2533
|
-
}
|
|
2684
|
+
});
|
|
2534
2685
|
}
|
|
2535
2686
|
}
|
|
2536
2687
|
}
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2688
|
+
return {
|
|
2689
|
+
paths,
|
|
2690
|
+
folderObj,
|
|
2691
|
+
};
|
|
2692
|
+
}
|
|
2693
|
+
catch (error) {
|
|
2694
|
+
console.log(error);
|
|
2695
|
+
return {};
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
array2TreeExport(idName = "id", pidName = "pid", modelsObj) {
|
|
2699
|
+
try {
|
|
2700
|
+
const { paths } = this.array2NamePathObj(idName, pidName, modelsObj);
|
|
2701
|
+
this.apiToSwaggerResult.paths = paths;
|
|
2702
|
+
}
|
|
2703
|
+
catch (error) {
|
|
2704
|
+
console.log(error);
|
|
2705
|
+
return [];
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
handleApis(modelsObj) {
|
|
2709
|
+
const apis = this.apiToSwaggerOrigin.apis;
|
|
2710
|
+
if (lodash.isArray(apis) && apis.length > 0) {
|
|
2711
|
+
this.array2TreeExport("target_id", "parent_id", modelsObj) || [];
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
apiToswagger(apipostObj, version, language) {
|
|
2715
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2716
|
+
// 初始化语言包
|
|
2717
|
+
yield I18nInit(language || 'en');
|
|
2718
|
+
this.apiToSwaggerOrigin = apipostObj;
|
|
2719
|
+
this.apiToSwaggerVersion = version;
|
|
2720
|
+
this.apiToSwaggerResult = {};
|
|
2721
|
+
if (`${version}` === "metersphere") {
|
|
2722
|
+
this.apiToSwaggerVersion = "3.0";
|
|
2723
|
+
}
|
|
2724
|
+
try {
|
|
2725
|
+
// 处理项目信息
|
|
2726
|
+
this.handleProject();
|
|
2727
|
+
// 处理数据模型
|
|
2728
|
+
const schemaMap = this.handleModels();
|
|
2729
|
+
// // 处理apis
|
|
2730
|
+
this.handleApis(schemaMap);
|
|
2731
|
+
// 处理环境信息
|
|
2732
|
+
this.handleEnvs();
|
|
2733
|
+
if (`${version}` === "metersphere") {
|
|
2734
|
+
this.formatData();
|
|
2735
|
+
}
|
|
2736
|
+
return throwResult$1("success", "", this.apiToSwaggerResult);
|
|
2737
|
+
}
|
|
2738
|
+
catch (error) {
|
|
2739
|
+
console.log(JSON.stringify(error.message), "error");
|
|
2740
|
+
return throwResult$1("error", String(error), this.apiToSwaggerResult);
|
|
2552
2741
|
}
|
|
2553
2742
|
});
|
|
2554
2743
|
}
|
|
2555
|
-
|
|
2556
|
-
is_check_result: 1,
|
|
2557
|
-
example,
|
|
2558
|
-
};
|
|
2559
|
-
};
|
|
2560
|
-
const completionWs2Config = () => {
|
|
2561
|
-
// if (isPlainObject(config)) {
|
|
2562
|
-
// return {
|
|
2563
|
-
// information_size: config?.information_size || 5,
|
|
2564
|
-
// certificate_verification: config?.certificate_verification || -1,
|
|
2565
|
-
// reconnect_num: config?.reconnect_num || 5,
|
|
2566
|
-
// reconnect_time: config?.reconnect_time || 5000,
|
|
2567
|
-
// shake_hands_timeout: config?.shake_hands_timeout || 0,
|
|
2568
|
-
// };
|
|
2569
|
-
// }
|
|
2570
|
-
return {
|
|
2571
|
-
certificate_verification: -1,
|
|
2572
|
-
information_size: 5,
|
|
2573
|
-
reconnect_num: 5,
|
|
2574
|
-
reconnect_time: 5000,
|
|
2575
|
-
shake_hands_timeout: 0,
|
|
2576
|
-
};
|
|
2577
|
-
};
|
|
2578
|
-
const completionSocketIoConfig = () => {
|
|
2579
|
-
// if (isPlainObject(config)) {
|
|
2580
|
-
// return {
|
|
2581
|
-
// reconnect_num: config?.reconnect_num || 5,
|
|
2582
|
-
// reconnect_time: config?.reconnect_time || 5000,
|
|
2583
|
-
// shake_hands_path: config?.shake_hands_path || '/socket.io',
|
|
2584
|
-
// shake_hands_timeout: config?.shake_hands_timeout || 0,
|
|
2585
|
-
// socket_version: config?.socket_version || 'v4',
|
|
2586
|
-
// certificate_verification: config?.certificate_verification || -1,
|
|
2587
|
-
// };
|
|
2588
|
-
// }
|
|
2589
|
-
return {
|
|
2590
|
-
reconnect_num: 5,
|
|
2591
|
-
reconnect_time: 5000,
|
|
2592
|
-
shake_hands_path: '/socket.io',
|
|
2593
|
-
shake_hands_timeout: 0,
|
|
2594
|
-
socket_version: 'v4',
|
|
2595
|
-
certificate_verification: -1,
|
|
2596
|
-
};
|
|
2597
|
-
};
|
|
2598
|
-
const completionWs2Request = (swaggerApi) => {
|
|
2599
|
-
const parameters = lodash.isArray(swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.parameters) ? swaggerApi.parameters : [];
|
|
2600
|
-
return {
|
|
2601
|
-
header: {
|
|
2602
|
-
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'header' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
2603
|
-
},
|
|
2604
|
-
query: {
|
|
2605
|
-
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'query' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
2606
|
-
},
|
|
2607
|
-
cookie: {
|
|
2608
|
-
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'cookie' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
2609
|
-
},
|
|
2610
|
-
};
|
|
2611
|
-
};
|
|
2612
|
-
const completionWs2Message = (swaggerApi) => {
|
|
2613
|
-
var _a;
|
|
2614
|
-
const content = ((_a = swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.requestBody) === null || _a === void 0 ? void 0 : _a.content) || {};
|
|
2615
|
-
const msg = lodash.values(content);
|
|
2616
|
-
return msg === null || msg === void 0 ? void 0 : msg.map((item) => {
|
|
2617
|
-
const response = (item === null || item === void 0 ? void 0 : item['x-response']) || {};
|
|
2618
|
-
return {
|
|
2619
|
-
name: (item === null || item === void 0 ? void 0 : item['x-summary']) || 'Message',
|
|
2620
|
-
param_id: apipostTools.snowflakeId(),
|
|
2621
|
-
request: {
|
|
2622
|
-
mode: (item === null || item === void 0 ? void 0 : item['x-mode']) || 'text',
|
|
2623
|
-
raw: (item === null || item === void 0 ? void 0 : item.example) || '',
|
|
2624
|
-
raw_parameter: [],
|
|
2625
|
-
raw_schema: (item === null || item === void 0 ? void 0 : item.schema) || {},
|
|
2626
|
-
},
|
|
2627
|
-
response: {
|
|
2628
|
-
mode: (response === null || response === void 0 ? void 0 : response['x-mode']) || 'text',
|
|
2629
|
-
raw: (response === null || response === void 0 ? void 0 : response.example) || '',
|
|
2630
|
-
raw_parameter: [],
|
|
2631
|
-
raw_schema: (response === null || response === void 0 ? void 0 : response.schema) || {},
|
|
2632
|
-
},
|
|
2633
|
-
};
|
|
2634
|
-
});
|
|
2635
|
-
};
|
|
2636
|
-
const completionSocketIoRequest = (swaggerApi) => {
|
|
2637
|
-
var _a;
|
|
2638
|
-
const parameters = lodash.isArray(swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.parameters) ? swaggerApi.parameters : [];
|
|
2639
|
-
return {
|
|
2640
|
-
header: {
|
|
2641
|
-
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'header' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
2642
|
-
},
|
|
2643
|
-
query: {
|
|
2644
|
-
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'query' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
2645
|
-
},
|
|
2646
|
-
cookie: {
|
|
2647
|
-
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'cookie' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
2648
|
-
},
|
|
2649
|
-
event: {
|
|
2650
|
-
parameter: lodash.isArray(parameters)
|
|
2651
|
-
? (_a = parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'event' && (p === null || p === void 0 ? void 0 : p.name))) === null || _a === void 0 ? void 0 : _a.map(({ description = '', schema = {}, is_checked = 1, name = '', example, required = true, }) => ({
|
|
2652
|
-
param_id: apipostTools.snowflakeId(),
|
|
2653
|
-
description,
|
|
2654
|
-
field_type: (schema === null || schema === void 0 ? void 0 : schema.type) || 'string',
|
|
2655
|
-
is_checked,
|
|
2656
|
-
key: name,
|
|
2657
|
-
value: lodash.isEqual(example, '1') ? example : '-1',
|
|
2658
|
-
not_null: required ? 1 : -1,
|
|
2659
|
-
}))
|
|
2660
|
-
: [],
|
|
2661
|
-
},
|
|
2662
|
-
};
|
|
2663
|
-
};
|
|
2664
|
-
const completionGraphqlRequestBody = (swaggerApi) => {
|
|
2665
|
-
var _a, _b;
|
|
2666
|
-
const content = ((_a = swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.requestBody) === null || _a === void 0 ? void 0 : _a.content) || {};
|
|
2667
|
-
const query_schema = ((_b = swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.requestBody) === null || _b === void 0 ? void 0 : _b['x-schema']) || {};
|
|
2668
|
-
return {
|
|
2669
|
-
query_list: lodash.values(content).map(item => {
|
|
2670
|
-
const response = (item === null || item === void 0 ? void 0 : item['x-response']) || {};
|
|
2671
|
-
return {
|
|
2672
|
-
param_id: apipostTools.snowflakeId(),
|
|
2673
|
-
name: item === null || item === void 0 ? void 0 : item['x-summary'],
|
|
2674
|
-
query: item === null || item === void 0 ? void 0 : item['x-query'],
|
|
2675
|
-
variables: item === null || item === void 0 ? void 0 : item['x-variables'],
|
|
2676
|
-
response: {
|
|
2677
|
-
mode: (response === null || response === void 0 ? void 0 : response['x-mode']) || 'json',
|
|
2678
|
-
raw: (response === null || response === void 0 ? void 0 : response.example) || '',
|
|
2679
|
-
raw_parameter: [],
|
|
2680
|
-
raw_schema: (response === null || response === void 0 ? void 0 : response.schema) || {},
|
|
2681
|
-
},
|
|
2682
|
-
};
|
|
2683
|
-
}),
|
|
2684
|
-
query_schema: lodash.isPlainObject(query_schema) ? query_schema : {},
|
|
2685
|
-
};
|
|
2686
|
-
};
|
|
2687
|
-
const completionGraphqlRequest = (swaggerApi) => {
|
|
2688
|
-
const parameters = lodash.isArray(swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.parameters) ? swaggerApi.parameters : [];
|
|
2689
|
-
return {
|
|
2690
|
-
header: {
|
|
2691
|
-
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'header' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
2692
|
-
},
|
|
2693
|
-
cookie: {
|
|
2694
|
-
parameter: completionParameter(parameters.filter(p => (p === null || p === void 0 ? void 0 : p.in) === 'cookie' && (p === null || p === void 0 ? void 0 : p.name))),
|
|
2695
|
-
},
|
|
2696
|
-
pre_tasks: [],
|
|
2697
|
-
post_tasks: [],
|
|
2698
|
-
body: completionGraphqlRequestBody(swaggerApi),
|
|
2699
|
-
};
|
|
2700
|
-
};
|
|
2701
|
-
const completionSocketMethodBody = (swaggerApi) => {
|
|
2702
|
-
var _a;
|
|
2703
|
-
const content = ((_a = swaggerApi === null || swaggerApi === void 0 ? void 0 : swaggerApi.requestBody) === null || _a === void 0 ? void 0 : _a.content) || {};
|
|
2704
|
-
const mode = lodash.isPlainObject(content) && !lodash.isEmpty(content) ? Object.keys(content)[0] : "none";
|
|
2705
|
-
const bodyData = (content === null || content === void 0 ? void 0 : content[mode]) || {};
|
|
2706
|
-
const apipostMode = (MODE_TYPE2 === null || MODE_TYPE2 === void 0 ? void 0 : MODE_TYPE2[mode]) || 'xml';
|
|
2707
|
-
return {
|
|
2708
|
-
mode: apipostMode,
|
|
2709
|
-
parameter: [],
|
|
2710
|
-
raw: (bodyData === null || bodyData === void 0 ? void 0 : bodyData.example) || '',
|
|
2711
|
-
raw_parameter: [],
|
|
2712
|
-
raw_schema: (bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema) || {},
|
|
2713
|
-
};
|
|
2714
|
-
};
|
|
2715
|
-
const completionSocketMethodRequest = (swaggerApi) => {
|
|
2716
|
-
return {
|
|
2717
|
-
body: completionSocketMethodBody(swaggerApi),
|
|
2718
|
-
post_tasks: [],
|
|
2719
|
-
configs: {
|
|
2720
|
-
charset: 'utf8',
|
|
2721
|
-
func: {
|
|
2722
|
-
request: [],
|
|
2723
|
-
response: [],
|
|
2724
|
-
},
|
|
2725
|
-
},
|
|
2726
|
-
};
|
|
2727
|
-
};
|
|
2744
|
+
}
|
|
2728
2745
|
|
|
2729
2746
|
class SwaggerToApipost {
|
|
2730
2747
|
constructor() {
|
|
@@ -7136,7 +7153,7 @@ class PostmanToApipost {
|
|
|
7136
7153
|
sort: 0,
|
|
7137
7154
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
7138
7155
|
method: completionMethod(request === null || request === void 0 ? void 0 : request.method),
|
|
7139
|
-
url: ((_c = request === null || request === void 0 ? void 0 : request.url) === null || _c === void 0 ? void 0 : _c.raw) || "",
|
|
7156
|
+
url: ((_c = request === null || request === void 0 ? void 0 : request.url) === null || _c === void 0 ? void 0 : _c.raw) || (lodash.isString(request === null || request === void 0 ? void 0 : request.url) ? request === null || request === void 0 ? void 0 : request.url : ""),
|
|
7140
7157
|
mark_id: "1",
|
|
7141
7158
|
protocol: "http/1.1",
|
|
7142
7159
|
request: this.completionApiRequest(item, {
|