json-machete 0.3.6-alpha-fd6e6eabc.0 → 0.3.6-alpha-e051434ff.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +53 -42
  2. package/index.mjs +53 -42
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -412,7 +412,9 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
412
412
  root: externalFile,
413
413
  });
414
414
  refMap.set($ref, result);
415
- result.$resolvedRef = $ref;
415
+ if (result && !result.$resolvedRef) {
416
+ result.$resolvedRef = refPath;
417
+ }
416
418
  if (obj.title) {
417
419
  result.title = obj.title;
418
420
  }
@@ -423,6 +425,9 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
423
425
  if (typeof resolvedObj === 'object' && !resolvedObj.$ref) {
424
426
  refMap.set($ref, resolvedObj);
425
427
  }
428
+ if (resolvedObj && !resolvedObj.$resolvedRef) {
429
+ resolvedObj.$resolvedRef = refPath;
430
+ }
426
431
  const result = await dereferenceObject(resolvedObj, {
427
432
  cwd,
428
433
  externalFileCache,
@@ -431,11 +436,10 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
431
436
  fetch,
432
437
  headers,
433
438
  });
434
- if (obj.title) {
435
- result.title = obj.title;
436
- }
437
439
  refMap.set($ref, result);
438
- result.$resolvedRef = $ref;
440
+ if (result && !result.$resolvedRef) {
441
+ result.$resolvedRef = refPath;
442
+ }
439
443
  return result;
440
444
  }
441
445
  }
@@ -509,43 +513,6 @@ async function healJSONSchema(schema) {
509
513
  if (duplicatedTypeNames.has(subSchema.title)) {
510
514
  delete subSchema.title;
511
515
  }
512
- if (!subSchema.title && !subSchema.$ref) {
513
- const realPath = subSchema.$resolvedRef || path;
514
- // Try to get definition name if missing
515
- const splitByDefinitions = path.includes('/components/schemas/')
516
- ? realPath.split('/components/schemas/')
517
- : realPath.split('/definitions/');
518
- const maybeDefinitionBasedPath = splitByDefinitions.length > 1 ? splitByDefinitions[splitByDefinitions.length - 1] : realPath;
519
- let pathBasedName = maybeDefinitionBasedPath
520
- .split('/properties')
521
- .join('')
522
- .split('/')
523
- .filter(Boolean)
524
- .join('_');
525
- switch (subSchema.type) {
526
- case 'string':
527
- // If it has special pattern, use path based name because it is specific
528
- if (subSchema.pattern || subSchema.maxLength || subSchema.minLength || subSchema.enum) {
529
- subSchema.title = pathBasedName;
530
- // Otherwise use the format name
531
- }
532
- else if (subSchema.format) {
533
- subSchema.title = subSchema.format;
534
- }
535
- break;
536
- case 'integer':
537
- // Use format name
538
- if (subSchema.format) {
539
- subSchema.title = subSchema.format;
540
- }
541
- break;
542
- }
543
- // If type name is reserved, add a suffix
544
- if (reservedTypeNames.includes(pathBasedName)) {
545
- pathBasedName += '_';
546
- }
547
- subSchema.title = subSchema.title || pathBasedName;
548
- }
549
516
  // Try to find the type
550
517
  if (!subSchema.type) {
551
518
  // If required exists without properties
@@ -598,6 +565,50 @@ async function healJSONSchema(schema) {
598
565
  }
599
566
  }
600
567
  }
568
+ if (!subSchema.title && !subSchema.$ref && subSchema.type !== 'array') {
569
+ const realPath = subSchema.$resolvedRef || path;
570
+ // Try to get definition name if missing
571
+ const splitByDefinitions = realPath.includes('/components/schemas/')
572
+ ? realPath.split('/components/schemas/')
573
+ : realPath.split('/definitions/');
574
+ const maybeDefinitionBasedPath = splitByDefinitions.length > 1 ? splitByDefinitions[splitByDefinitions.length - 1] : realPath;
575
+ let pathBasedName = maybeDefinitionBasedPath
576
+ .split('~1')
577
+ .join('/')
578
+ .split('/properties')
579
+ .join('')
580
+ .split('-')
581
+ .join('_')
582
+ .split('/')
583
+ .filter(Boolean)
584
+ .join('_');
585
+ switch (subSchema.type) {
586
+ case 'string':
587
+ // If it has special pattern, use path based name because it is specific
588
+ if (subSchema.pattern || subSchema.maxLength || subSchema.minLength || subSchema.enum) {
589
+ subSchema.title = pathBasedName;
590
+ // Otherwise use the format name
591
+ }
592
+ else if (subSchema.format) {
593
+ subSchema.title = subSchema.format;
594
+ }
595
+ break;
596
+ case 'integer':
597
+ // Use format name
598
+ if (subSchema.format) {
599
+ subSchema.title = subSchema.format;
600
+ }
601
+ break;
602
+ case 'array':
603
+ break;
604
+ default:
605
+ subSchema.title = subSchema.title || pathBasedName;
606
+ }
607
+ // If type name is reserved, add a suffix
608
+ if (reservedTypeNames.includes(pathBasedName)) {
609
+ pathBasedName += '_';
610
+ }
611
+ }
601
612
  }
602
613
  return subSchema;
603
614
  }, {
package/index.mjs CHANGED
@@ -407,7 +407,9 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
407
407
  root: externalFile,
408
408
  });
409
409
  refMap.set($ref, result);
410
- result.$resolvedRef = $ref;
410
+ if (result && !result.$resolvedRef) {
411
+ result.$resolvedRef = refPath;
412
+ }
411
413
  if (obj.title) {
412
414
  result.title = obj.title;
413
415
  }
@@ -418,6 +420,9 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
418
420
  if (typeof resolvedObj === 'object' && !resolvedObj.$ref) {
419
421
  refMap.set($ref, resolvedObj);
420
422
  }
423
+ if (resolvedObj && !resolvedObj.$resolvedRef) {
424
+ resolvedObj.$resolvedRef = refPath;
425
+ }
421
426
  const result = await dereferenceObject(resolvedObj, {
422
427
  cwd,
423
428
  externalFileCache,
@@ -426,11 +431,10 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
426
431
  fetch: fetch$1,
427
432
  headers,
428
433
  });
429
- if (obj.title) {
430
- result.title = obj.title;
431
- }
432
434
  refMap.set($ref, result);
433
- result.$resolvedRef = $ref;
435
+ if (result && !result.$resolvedRef) {
436
+ result.$resolvedRef = refPath;
437
+ }
434
438
  return result;
435
439
  }
436
440
  }
@@ -504,43 +508,6 @@ async function healJSONSchema(schema) {
504
508
  if (duplicatedTypeNames.has(subSchema.title)) {
505
509
  delete subSchema.title;
506
510
  }
507
- if (!subSchema.title && !subSchema.$ref) {
508
- const realPath = subSchema.$resolvedRef || path;
509
- // Try to get definition name if missing
510
- const splitByDefinitions = path.includes('/components/schemas/')
511
- ? realPath.split('/components/schemas/')
512
- : realPath.split('/definitions/');
513
- const maybeDefinitionBasedPath = splitByDefinitions.length > 1 ? splitByDefinitions[splitByDefinitions.length - 1] : realPath;
514
- let pathBasedName = maybeDefinitionBasedPath
515
- .split('/properties')
516
- .join('')
517
- .split('/')
518
- .filter(Boolean)
519
- .join('_');
520
- switch (subSchema.type) {
521
- case 'string':
522
- // If it has special pattern, use path based name because it is specific
523
- if (subSchema.pattern || subSchema.maxLength || subSchema.minLength || subSchema.enum) {
524
- subSchema.title = pathBasedName;
525
- // Otherwise use the format name
526
- }
527
- else if (subSchema.format) {
528
- subSchema.title = subSchema.format;
529
- }
530
- break;
531
- case 'integer':
532
- // Use format name
533
- if (subSchema.format) {
534
- subSchema.title = subSchema.format;
535
- }
536
- break;
537
- }
538
- // If type name is reserved, add a suffix
539
- if (reservedTypeNames.includes(pathBasedName)) {
540
- pathBasedName += '_';
541
- }
542
- subSchema.title = subSchema.title || pathBasedName;
543
- }
544
511
  // Try to find the type
545
512
  if (!subSchema.type) {
546
513
  // If required exists without properties
@@ -593,6 +560,50 @@ async function healJSONSchema(schema) {
593
560
  }
594
561
  }
595
562
  }
563
+ if (!subSchema.title && !subSchema.$ref && subSchema.type !== 'array') {
564
+ const realPath = subSchema.$resolvedRef || path;
565
+ // Try to get definition name if missing
566
+ const splitByDefinitions = realPath.includes('/components/schemas/')
567
+ ? realPath.split('/components/schemas/')
568
+ : realPath.split('/definitions/');
569
+ const maybeDefinitionBasedPath = splitByDefinitions.length > 1 ? splitByDefinitions[splitByDefinitions.length - 1] : realPath;
570
+ let pathBasedName = maybeDefinitionBasedPath
571
+ .split('~1')
572
+ .join('/')
573
+ .split('/properties')
574
+ .join('')
575
+ .split('-')
576
+ .join('_')
577
+ .split('/')
578
+ .filter(Boolean)
579
+ .join('_');
580
+ switch (subSchema.type) {
581
+ case 'string':
582
+ // If it has special pattern, use path based name because it is specific
583
+ if (subSchema.pattern || subSchema.maxLength || subSchema.minLength || subSchema.enum) {
584
+ subSchema.title = pathBasedName;
585
+ // Otherwise use the format name
586
+ }
587
+ else if (subSchema.format) {
588
+ subSchema.title = subSchema.format;
589
+ }
590
+ break;
591
+ case 'integer':
592
+ // Use format name
593
+ if (subSchema.format) {
594
+ subSchema.title = subSchema.format;
595
+ }
596
+ break;
597
+ case 'array':
598
+ break;
599
+ default:
600
+ subSchema.title = subSchema.title || pathBasedName;
601
+ }
602
+ // If type name is reserved, add a suffix
603
+ if (reservedTypeNames.includes(pathBasedName)) {
604
+ pathBasedName += '_';
605
+ }
606
+ }
596
607
  }
597
608
  return subSchema;
598
609
  }, {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "json-machete",
3
- "version": "0.3.6-alpha-fd6e6eabc.0",
3
+ "version": "0.3.6-alpha-e051434ff.0",
4
4
  "sideEffects": false,
5
5
  "dependencies": {
6
6
  "@graphql-mesh/utils": "0.26.0",
7
7
  "@json-schema-tools/meta-schema": "1.6.19",
8
- "cross-undici-fetch": "0.1.15",
8
+ "cross-undici-fetch": "0.1.16",
9
9
  "json-ptr": "3.0.1",
10
10
  "to-json-schema": "0.2.5",
11
11
  "url-join": "4.0.1"