json-machete 0.5.8-alpha-e1a6613fa.0 → 0.5.8-alpha-65177bb68.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 +14 -8
  2. package/index.mjs +14 -8
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -532,6 +532,15 @@ async function healJSONSchema(schema) {
532
532
  const duplicatedTypeNames = await getDeduplicatedTitles(deduplicatedSchema);
533
533
  return visitJSONSchema(deduplicatedSchema, (subSchema, { path }) => {
534
534
  if (typeof subSchema === 'object') {
535
+ // Some JSON Schemas use this broken pattern and refer the type using `items`
536
+ if (subSchema.type === 'object' && subSchema.items) {
537
+ const realSubschema = subSchema.items;
538
+ delete subSchema.items;
539
+ return realSubschema;
540
+ }
541
+ if (subSchema.properties && subSchema.type !== 'object') {
542
+ subSchema.type = 'object';
543
+ }
535
544
  if (duplicatedTypeNames.has(subSchema.title)) {
536
545
  delete subSchema.title;
537
546
  }
@@ -561,10 +570,6 @@ async function healJSONSchema(schema) {
561
570
  subSchema.type = 'array';
562
571
  }
563
572
  }
564
- // Some JSON Schemas use this broken pattern and refer the type using `items`
565
- if (subSchema.type !== 'array' && subSchema.items) {
566
- subSchema.type = 'array';
567
- }
568
573
  // If it is an object type but no properties given while example is available
569
574
  if (subSchema.type === 'object' && !subSchema.properties && subSchema.example) {
570
575
  const generatedSchema = toJsonSchema(subSchema.example, {
@@ -587,7 +592,7 @@ async function healJSONSchema(schema) {
587
592
  }
588
593
  }
589
594
  }
590
- if (!subSchema.title && !subSchema.$ref && subSchema.type !== 'array') {
595
+ if (!subSchema.title && !subSchema.$ref && subSchema.type !== 'array' && !subSchema.items) {
591
596
  const realPath = subSchema.$resolvedRef || path;
592
597
  // Try to get definition name if missing
593
598
  const splitByDefinitions = realPath.includes('/components/schemas/')
@@ -659,7 +664,7 @@ async function referenceJSONSchema(schema) {
659
664
  while (`${subSchema.title}${cnt}` in definitions) {
660
665
  cnt++;
661
666
  }
662
- const definitionProp = `${subSchema.title}${cnt}`;
667
+ const definitionProp = `${subSchema.title}${cnt}`.split(' ').join('_SPACE_');
663
668
  definitions[definitionProp] = subSchema;
664
669
  const $ref = `#/definitions/${definitionProp}`;
665
670
  return {
@@ -667,8 +672,9 @@ async function referenceJSONSchema(schema) {
667
672
  };
668
673
  }
669
674
  else {
670
- definitions[subSchema.title] = subSchema;
671
- const $ref = `#/definitions/${subSchema.title}`;
675
+ const definitionProp = subSchema.title.split(' ').join('_SPACE_');
676
+ definitions[definitionProp] = subSchema;
677
+ const $ref = `#/definitions/${definitionProp}`;
672
678
  return {
673
679
  $ref,
674
680
  };
package/index.mjs CHANGED
@@ -527,6 +527,15 @@ async function healJSONSchema(schema) {
527
527
  const duplicatedTypeNames = await getDeduplicatedTitles(deduplicatedSchema);
528
528
  return visitJSONSchema(deduplicatedSchema, (subSchema, { path }) => {
529
529
  if (typeof subSchema === 'object') {
530
+ // Some JSON Schemas use this broken pattern and refer the type using `items`
531
+ if (subSchema.type === 'object' && subSchema.items) {
532
+ const realSubschema = subSchema.items;
533
+ delete subSchema.items;
534
+ return realSubschema;
535
+ }
536
+ if (subSchema.properties && subSchema.type !== 'object') {
537
+ subSchema.type = 'object';
538
+ }
530
539
  if (duplicatedTypeNames.has(subSchema.title)) {
531
540
  delete subSchema.title;
532
541
  }
@@ -556,10 +565,6 @@ async function healJSONSchema(schema) {
556
565
  subSchema.type = 'array';
557
566
  }
558
567
  }
559
- // Some JSON Schemas use this broken pattern and refer the type using `items`
560
- if (subSchema.type !== 'array' && subSchema.items) {
561
- subSchema.type = 'array';
562
- }
563
568
  // If it is an object type but no properties given while example is available
564
569
  if (subSchema.type === 'object' && !subSchema.properties && subSchema.example) {
565
570
  const generatedSchema = toJsonSchema(subSchema.example, {
@@ -582,7 +587,7 @@ async function healJSONSchema(schema) {
582
587
  }
583
588
  }
584
589
  }
585
- if (!subSchema.title && !subSchema.$ref && subSchema.type !== 'array') {
590
+ if (!subSchema.title && !subSchema.$ref && subSchema.type !== 'array' && !subSchema.items) {
586
591
  const realPath = subSchema.$resolvedRef || path;
587
592
  // Try to get definition name if missing
588
593
  const splitByDefinitions = realPath.includes('/components/schemas/')
@@ -654,7 +659,7 @@ async function referenceJSONSchema(schema) {
654
659
  while (`${subSchema.title}${cnt}` in definitions) {
655
660
  cnt++;
656
661
  }
657
- const definitionProp = `${subSchema.title}${cnt}`;
662
+ const definitionProp = `${subSchema.title}${cnt}`.split(' ').join('_SPACE_');
658
663
  definitions[definitionProp] = subSchema;
659
664
  const $ref = `#/definitions/${definitionProp}`;
660
665
  return {
@@ -662,8 +667,9 @@ async function referenceJSONSchema(schema) {
662
667
  };
663
668
  }
664
669
  else {
665
- definitions[subSchema.title] = subSchema;
666
- const $ref = `#/definitions/${subSchema.title}`;
670
+ const definitionProp = subSchema.title.split(' ').join('_SPACE_');
671
+ definitions[definitionProp] = subSchema;
672
+ const $ref = `#/definitions/${definitionProp}`;
667
673
  return {
668
674
  $ref,
669
675
  };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "json-machete",
3
- "version": "0.5.8-alpha-e1a6613fa.0",
3
+ "version": "0.5.8-alpha-65177bb68.0",
4
4
  "sideEffects": false,
5
5
  "dependencies": {
6
- "@graphql-mesh/utils": "0.27.7-alpha-e1a6613fa.0",
6
+ "@graphql-mesh/utils": "0.27.6",
7
7
  "@json-schema-tools/meta-schema": "1.6.19",
8
8
  "cross-undici-fetch": "0.1.25",
9
9
  "json-ptr": "3.1.0",