wrekenfile-converter 2.0.4 → 2.0.6
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.
|
@@ -427,8 +427,8 @@ function extractInterfaces(spec) {
|
|
|
427
427
|
const returns = extractResponses(op, operationId, method, pathStr);
|
|
428
428
|
interfaces[alias] = {
|
|
429
429
|
SUMMARY: op.summary || '',
|
|
430
|
-
DESCRIPTION: op.description || '',
|
|
431
430
|
DESC: generateDesc(op, method, pathStr),
|
|
431
|
+
TAGS: Array.isArray(op.tags) ? op.tags : [],
|
|
432
432
|
ENDPOINT: endpoint,
|
|
433
433
|
VISIBILITY: visibility,
|
|
434
434
|
HTTP: {
|
|
@@ -70,11 +70,23 @@ function mapType(value) {
|
|
|
70
70
|
return 'ANY';
|
|
71
71
|
return 'ANY';
|
|
72
72
|
}
|
|
73
|
+
function getItemDescription(item) {
|
|
74
|
+
var _a, _b, _c, _d, _e;
|
|
75
|
+
let description = (_c = (_a = item === null || item === void 0 ? void 0 : item.description) !== null && _a !== void 0 ? _a : (_b = item === null || item === void 0 ? void 0 : item.request) === null || _b === void 0 ? void 0 : _b.description) !== null && _c !== void 0 ? _c : (_e = (_d = item === null || item === void 0 ? void 0 : item.request) === null || _d === void 0 ? void 0 : _d.body) === null || _e === void 0 ? void 0 : _e.description;
|
|
76
|
+
if (!description)
|
|
77
|
+
return '';
|
|
78
|
+
// Postman can store description as an object with { content: string }
|
|
79
|
+
if (typeof description === 'object' && typeof description.content === 'string') {
|
|
80
|
+
description = description.content;
|
|
81
|
+
}
|
|
82
|
+
if (typeof description !== 'string')
|
|
83
|
+
return '';
|
|
84
|
+
return description.replace(/<[^>]*>/g, '').replace(/\n+/g, ' ').trim();
|
|
85
|
+
}
|
|
73
86
|
function generateDesc(item, method, path) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return
|
|
77
|
-
}
|
|
87
|
+
const cleaned = getItemDescription(item);
|
|
88
|
+
if (cleaned)
|
|
89
|
+
return cleaned;
|
|
78
90
|
return `${method.toUpperCase()} ${path}`;
|
|
79
91
|
}
|
|
80
92
|
function generateStructName(itemName, method, path, suffix) {
|
|
@@ -423,12 +435,13 @@ function extractOperations(collection, variables) {
|
|
|
423
435
|
return `${name} ${operationNameCount[name]}`;
|
|
424
436
|
}
|
|
425
437
|
}
|
|
426
|
-
function processItem(item) {
|
|
438
|
+
function processItem(item, parentName = null) {
|
|
427
439
|
if (item.request) {
|
|
428
440
|
const method = item.request.method || 'GET';
|
|
429
441
|
const url = item.request.url;
|
|
430
442
|
const path = extractPathFromUrl(url, variables);
|
|
431
443
|
const itemName = item.name || 'unknown';
|
|
444
|
+
const immediateParentName = parentName || null;
|
|
432
445
|
// Generate operation ID
|
|
433
446
|
let operationId = itemName.toLowerCase().replace(/[^a-z0-9]/g, '-');
|
|
434
447
|
operationId = getUniqueOperationName(operationId);
|
|
@@ -444,8 +457,8 @@ function extractOperations(collection, variables) {
|
|
|
444
457
|
operations.push({
|
|
445
458
|
name: operationId,
|
|
446
459
|
SUMMARY: itemName || '',
|
|
447
|
-
DESCRIPTION: item.description ? item.description.replace(/<[^>]*>/g, '').replace(/\n+/g, ' ').trim() : '',
|
|
448
460
|
DESC: generateDesc(item, method, path),
|
|
461
|
+
TAGS: immediateParentName ? [immediateParentName] : (itemName ? [itemName] : []),
|
|
449
462
|
ENDPOINT: `"/${path}"`,
|
|
450
463
|
VISIBILITY: 'PUBLIC',
|
|
451
464
|
HTTP: {
|
|
@@ -459,12 +472,12 @@ function extractOperations(collection, variables) {
|
|
|
459
472
|
}
|
|
460
473
|
if (item.item) {
|
|
461
474
|
for (const subItem of item.item) {
|
|
462
|
-
processItem(subItem);
|
|
475
|
+
processItem(subItem, item.name || parentName || null);
|
|
463
476
|
}
|
|
464
477
|
}
|
|
465
478
|
}
|
|
466
479
|
for (const item of collection.item) {
|
|
467
|
-
processItem(item);
|
|
480
|
+
processItem(item, null);
|
|
468
481
|
}
|
|
469
482
|
return operations;
|
|
470
483
|
}
|
|
@@ -531,13 +544,24 @@ function generateWrekenfile(collection, variables) {
|
|
|
531
544
|
wrekenfile += `INTERFACES:\n`;
|
|
532
545
|
for (const operation of operations) {
|
|
533
546
|
wrekenfile += ` ${operation.name}:\n`;
|
|
534
|
-
// Quote SUMMARY and
|
|
547
|
+
// Quote SUMMARY and DESC if they contain special characters
|
|
535
548
|
const summary = operation.SUMMARY.includes(':') || operation.SUMMARY.includes('"') ? `"${operation.SUMMARY.replace(/"/g, '\\"')}"` : operation.SUMMARY;
|
|
536
|
-
const description = operation.DESCRIPTION.includes(':') || operation.DESCRIPTION.includes('"') ? `"${operation.DESCRIPTION.replace(/"/g, '\\"')}"` : operation.DESCRIPTION;
|
|
537
549
|
const desc = operation.DESC.includes(':') || operation.DESC.includes('"') ? `"${operation.DESC.replace(/"/g, '\\"')}"` : operation.DESC;
|
|
538
550
|
wrekenfile += ` SUMMARY: ${summary}\n`;
|
|
539
|
-
wrekenfile += ` DESCRIPTION: ${description}\n`;
|
|
540
551
|
wrekenfile += ` DESC: ${desc}\n`;
|
|
552
|
+
// TAGS
|
|
553
|
+
if (!operation.TAGS || operation.TAGS.length === 0) {
|
|
554
|
+
wrekenfile += ` TAGS: []\n`;
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
wrekenfile += ` TAGS:\n`;
|
|
558
|
+
for (const tag of operation.TAGS) {
|
|
559
|
+
const tagVal = (typeof tag === 'string' && (tag.includes(':') || tag.includes('"')))
|
|
560
|
+
? `"${String(tag).replace(/"/g, '\\"')}"`
|
|
561
|
+
: String(tag);
|
|
562
|
+
wrekenfile += ` - ${tagVal}\n`;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
541
565
|
wrekenfile += ` ENDPOINT: ${operation.ENDPOINT}\n`;
|
|
542
566
|
wrekenfile += ` VISIBILITY: ${operation.VISIBILITY}\n`;
|
|
543
567
|
wrekenfile += ` HTTP:\n`;
|
package/package.json
CHANGED