wrekenfile-converter 2.0.4 → 2.0.7

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
- if (item.description) {
75
- // Remove HTML tags and clean up description
76
- return item.description.replace(/<[^>]*>/g, '').replace(/\n+/g, ' ').trim();
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
  }
@@ -501,7 +514,6 @@ function validateYaml(yamlString) {
501
514
  }
502
515
  }
503
516
  function generateWrekenfile(collection, variables) {
504
- var _a;
505
517
  if (!collection || typeof collection !== 'object') {
506
518
  throw new Error("Argument 'collection' is required and must be an object");
507
519
  }
@@ -531,13 +543,22 @@ function generateWrekenfile(collection, variables) {
531
543
  wrekenfile += `INTERFACES:\n`;
532
544
  for (const operation of operations) {
533
545
  wrekenfile += ` ${operation.name}:\n`;
534
- // Quote SUMMARY and DESCRIPTION if they contain special characters
535
- 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
- const desc = operation.DESC.includes(':') || operation.DESC.includes('"') ? `"${operation.DESC.replace(/"/g, '\\"')}"` : operation.DESC;
546
+ // Always quote SUMMARY and DESC to avoid YAML parse issues
547
+ const summary = `"${String(operation.SUMMARY || '').replace(/"/g, '\\"')}"`;
548
+ const desc = `"${String(operation.DESC || '').replace(/"/g, '\\"')}"`;
538
549
  wrekenfile += ` SUMMARY: ${summary}\n`;
539
- wrekenfile += ` DESCRIPTION: ${description}\n`;
540
550
  wrekenfile += ` DESC: ${desc}\n`;
551
+ // TAGS
552
+ if (!operation.TAGS || operation.TAGS.length === 0) {
553
+ wrekenfile += ` TAGS: []\n`;
554
+ }
555
+ else {
556
+ wrekenfile += ` TAGS:\n`;
557
+ for (const tag of operation.TAGS) {
558
+ const tagVal = `"${String(tag).replace(/"/g, '\\"')}"`;
559
+ wrekenfile += ` - ${tagVal}\n`;
560
+ }
561
+ }
541
562
  wrekenfile += ` ENDPOINT: ${operation.ENDPOINT}\n`;
542
563
  wrekenfile += ` VISIBILITY: ${operation.VISIBILITY}\n`;
543
564
  wrekenfile += ` HTTP:\n`;
@@ -557,7 +578,7 @@ function generateWrekenfile(collection, variables) {
557
578
  wrekenfile += ` INPUTS:\n`;
558
579
  for (const input of operation.INPUTS) {
559
580
  wrekenfile += ` - name: ${input.name}\n`;
560
- wrekenfile += ` type: ${input.type}\n`;
581
+ wrekenfile += ` type: "${String(input.type).replace(/"/g, '\\"')}"\n`;
561
582
  wrekenfile += ` required: '${input.required}'\n`;
562
583
  if (input.location) {
563
584
  wrekenfile += ` location: ${input.location}\n`;
@@ -567,7 +588,7 @@ function generateWrekenfile(collection, variables) {
567
588
  // RETURNS
568
589
  wrekenfile += ` RETURNS:\n`;
569
590
  for (const ret of operation.RETURNS) {
570
- wrekenfile += ` - RETURNTYPE: ${ret.RETURNTYPE}\n`;
591
+ wrekenfile += ` - RETURNTYPE: "${String(ret.RETURNTYPE).replace(/"/g, '\\"')}"\n`;
571
592
  wrekenfile += ` RETURNNAME: ${ret.RETURNNAME}\n`;
572
593
  wrekenfile += ` CODE: '${ret.CODE}'\n`;
573
594
  }
@@ -581,22 +602,13 @@ function generateWrekenfile(collection, variables) {
581
602
  wrekenfile += ` ${structName}:\n`;
582
603
  for (const field of fields) {
583
604
  wrekenfile += ' - name: ' + field.name + '\n';
584
- // Quote type if it contains non-alphanumeric characters (except underscore)
585
- let typeValue = field.type;
586
- if (/[^a-zA-Z0-9_]/.test(typeValue)) {
587
- typeValue = '"' + typeValue.replace(/"/g, '\"') + '"';
588
- }
605
+ const typeValue = '"' + String(field.type).replace(/"/g, '\\"') + '"';
589
606
  wrekenfile += ' type: ' + typeValue + '\n';
590
607
  wrekenfile += " required: '" + field.required + "'\n";
591
608
  }
592
609
  }
593
610
  }
594
611
  // Debug print: show first 20 lines of STRUCTS block
595
- const structsBlock = (_a = wrekenfile.split('STRUCTS:')[1]) === null || _a === void 0 ? void 0 : _a.split('\n').slice(0, 20).join('\n');
596
- if (structsBlock) {
597
- console.log('--- STRUCTS block preview ---');
598
- console.log(structsBlock);
599
- }
600
612
  wrekenfile = cleanYaml(wrekenfile);
601
613
  checkYamlForHiddenChars(wrekenfile);
602
614
  validateYaml(wrekenfile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrekenfile-converter",
3
- "version": "2.0.4",
3
+ "version": "2.0.7",
4
4
  "description": "Convert OpenAPI and Postman specs to Wrekenfile format with mini-chunking for vector DB storage",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",