json-machete 0.3.6-alpha-429c0ee6b.0 → 0.3.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.
Files changed (3) hide show
  1. package/index.js +44 -42
  2. package/index.mjs +44 -42
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -436,9 +436,6 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
436
436
  fetch,
437
437
  headers,
438
438
  });
439
- if (obj.title) {
440
- result.title = obj.title;
441
- }
442
439
  refMap.set($ref, result);
443
440
  if (result && !result.$resolvedRef) {
444
441
  result.$resolvedRef = refPath;
@@ -516,45 +513,6 @@ async function healJSONSchema(schema) {
516
513
  if (duplicatedTypeNames.has(subSchema.title)) {
517
514
  delete subSchema.title;
518
515
  }
519
- if (!subSchema.title && !subSchema.$ref) {
520
- const realPath = subSchema.$resolvedRef || path;
521
- // Try to get definition name if missing
522
- const splitByDefinitions = path.includes('/components/schemas/')
523
- ? realPath.split('/components/schemas/')
524
- : realPath.split('/definitions/');
525
- const maybeDefinitionBasedPath = splitByDefinitions.length > 1 ? splitByDefinitions[splitByDefinitions.length - 1] : realPath;
526
- let pathBasedName = maybeDefinitionBasedPath
527
- .split('/properties')
528
- .join('')
529
- .split('-')
530
- .join('_')
531
- .split('/')
532
- .filter(Boolean)
533
- .join('_');
534
- switch (subSchema.type) {
535
- case 'string':
536
- // If it has special pattern, use path based name because it is specific
537
- if (subSchema.pattern || subSchema.maxLength || subSchema.minLength || subSchema.enum) {
538
- subSchema.title = pathBasedName;
539
- // Otherwise use the format name
540
- }
541
- else if (subSchema.format) {
542
- subSchema.title = subSchema.format;
543
- }
544
- break;
545
- case 'integer':
546
- // Use format name
547
- if (subSchema.format) {
548
- subSchema.title = subSchema.format;
549
- }
550
- break;
551
- }
552
- // If type name is reserved, add a suffix
553
- if (reservedTypeNames.includes(pathBasedName)) {
554
- pathBasedName += '_';
555
- }
556
- subSchema.title = subSchema.title || pathBasedName;
557
- }
558
516
  // Try to find the type
559
517
  if (!subSchema.type) {
560
518
  // If required exists without properties
@@ -607,6 +565,50 @@ async function healJSONSchema(schema) {
607
565
  }
608
566
  }
609
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
+ }
610
612
  }
611
613
  return subSchema;
612
614
  }, {
package/index.mjs CHANGED
@@ -431,9 +431,6 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
431
431
  fetch: fetch$1,
432
432
  headers,
433
433
  });
434
- if (obj.title) {
435
- result.title = obj.title;
436
- }
437
434
  refMap.set($ref, result);
438
435
  if (result && !result.$resolvedRef) {
439
436
  result.$resolvedRef = refPath;
@@ -511,45 +508,6 @@ async function healJSONSchema(schema) {
511
508
  if (duplicatedTypeNames.has(subSchema.title)) {
512
509
  delete subSchema.title;
513
510
  }
514
- if (!subSchema.title && !subSchema.$ref) {
515
- const realPath = subSchema.$resolvedRef || path;
516
- // Try to get definition name if missing
517
- const splitByDefinitions = path.includes('/components/schemas/')
518
- ? realPath.split('/components/schemas/')
519
- : realPath.split('/definitions/');
520
- const maybeDefinitionBasedPath = splitByDefinitions.length > 1 ? splitByDefinitions[splitByDefinitions.length - 1] : realPath;
521
- let pathBasedName = maybeDefinitionBasedPath
522
- .split('/properties')
523
- .join('')
524
- .split('-')
525
- .join('_')
526
- .split('/')
527
- .filter(Boolean)
528
- .join('_');
529
- switch (subSchema.type) {
530
- case 'string':
531
- // If it has special pattern, use path based name because it is specific
532
- if (subSchema.pattern || subSchema.maxLength || subSchema.minLength || subSchema.enum) {
533
- subSchema.title = pathBasedName;
534
- // Otherwise use the format name
535
- }
536
- else if (subSchema.format) {
537
- subSchema.title = subSchema.format;
538
- }
539
- break;
540
- case 'integer':
541
- // Use format name
542
- if (subSchema.format) {
543
- subSchema.title = subSchema.format;
544
- }
545
- break;
546
- }
547
- // If type name is reserved, add a suffix
548
- if (reservedTypeNames.includes(pathBasedName)) {
549
- pathBasedName += '_';
550
- }
551
- subSchema.title = subSchema.title || pathBasedName;
552
- }
553
511
  // Try to find the type
554
512
  if (!subSchema.type) {
555
513
  // If required exists without properties
@@ -602,6 +560,50 @@ async function healJSONSchema(schema) {
602
560
  }
603
561
  }
604
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
+ }
605
607
  }
606
608
  return subSchema;
607
609
  }, {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "json-machete",
3
- "version": "0.3.6-alpha-429c0ee6b.0",
3
+ "version": "0.3.6",
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"