json-machete 0.7.12-alpha-cae8e1530.0 → 0.7.12
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.
- package/index.js +6 -48
- package/index.mjs +6 -48
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -546,48 +546,8 @@ async function getDeduplicatedTitles(schema) {
|
|
|
546
546
|
async function healJSONSchema(schema) {
|
|
547
547
|
const deduplicatedSchema = deduplicateJSONSchema(schema);
|
|
548
548
|
const duplicatedTypeNames = await getDeduplicatedTitles(deduplicatedSchema);
|
|
549
|
-
return visitJSONSchema(deduplicatedSchema,
|
|
549
|
+
return visitJSONSchema(deduplicatedSchema, (subSchema, { path }) => {
|
|
550
550
|
if (typeof subSchema === 'object') {
|
|
551
|
-
// We don't support following properties
|
|
552
|
-
delete subSchema.readOnly;
|
|
553
|
-
delete subSchema.writeOnly;
|
|
554
|
-
const keys = Object.keys(subSchema);
|
|
555
|
-
if (keys.length === 0) {
|
|
556
|
-
subSchema.type = 'object';
|
|
557
|
-
subSchema.additionalProperties = true;
|
|
558
|
-
}
|
|
559
|
-
if (typeof subSchema.additionalProperties === 'object') {
|
|
560
|
-
delete subSchema.additionalProperties.readOnly;
|
|
561
|
-
delete subSchema.additionalProperties.writeOnly;
|
|
562
|
-
if (!subSchema.additionalProperties.type) {
|
|
563
|
-
console.log(path, Object.keys(subSchema.additionalProperties));
|
|
564
|
-
}
|
|
565
|
-
if (Object.keys(subSchema.additionalProperties).length === 0) {
|
|
566
|
-
subSchema.additionalProperties = true;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
if (subSchema.allOf != null && subSchema.allOf.length === 1) {
|
|
570
|
-
const realSubschema = subSchema.allOf[0];
|
|
571
|
-
delete subSchema.allOf;
|
|
572
|
-
return realSubschema;
|
|
573
|
-
}
|
|
574
|
-
if (subSchema.anyOf != null && subSchema.anyOf.length === 1) {
|
|
575
|
-
const realSubschema = subSchema.anyOf[0];
|
|
576
|
-
delete subSchema.anyOf;
|
|
577
|
-
return realSubschema;
|
|
578
|
-
}
|
|
579
|
-
if (subSchema.oneOf != null && subSchema.oneOf.length === 1) {
|
|
580
|
-
const realSubschema = subSchema.oneOf[0];
|
|
581
|
-
delete subSchema.oneOf;
|
|
582
|
-
return realSubschema;
|
|
583
|
-
}
|
|
584
|
-
if (subSchema.description != null) {
|
|
585
|
-
subSchema.description = subSchema.description.trim();
|
|
586
|
-
if (keys.length === 1) {
|
|
587
|
-
subSchema.type = 'object';
|
|
588
|
-
subSchema.additionalProperties = true;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
551
|
// Some JSON Schemas use this broken pattern and refer the type using `items`
|
|
592
552
|
if (subSchema.type === 'object' && subSchema.items) {
|
|
593
553
|
const realSubschema = subSchema.items;
|
|
@@ -600,9 +560,6 @@ async function healJSONSchema(schema) {
|
|
|
600
560
|
if (duplicatedTypeNames.has(subSchema.title)) {
|
|
601
561
|
delete subSchema.title;
|
|
602
562
|
}
|
|
603
|
-
if (typeof subSchema.example === 'object' && !subSchema.type) {
|
|
604
|
-
subSchema.type = 'object';
|
|
605
|
-
}
|
|
606
563
|
// Try to find the type
|
|
607
564
|
if (!subSchema.type) {
|
|
608
565
|
// If required exists without properties
|
|
@@ -658,7 +615,7 @@ async function healJSONSchema(schema) {
|
|
|
658
615
|
}
|
|
659
616
|
}
|
|
660
617
|
// If it is an object type but no properties given while example is available
|
|
661
|
-
if (
|
|
618
|
+
if (subSchema.type === 'object' && !subSchema.properties && subSchema.example) {
|
|
662
619
|
const generatedSchema = toJsonSchema(subSchema.example, {
|
|
663
620
|
required: false,
|
|
664
621
|
objects: {
|
|
@@ -671,9 +628,7 @@ async function healJSONSchema(schema) {
|
|
|
671
628
|
mode: 'first',
|
|
672
629
|
},
|
|
673
630
|
});
|
|
674
|
-
|
|
675
|
-
subSchema.type = asArray(healedGeneratedSchema.type)[0];
|
|
676
|
-
subSchema.properties = healedGeneratedSchema.properties;
|
|
631
|
+
subSchema.properties = generatedSchema.properties;
|
|
677
632
|
// If type for properties is already given, use it
|
|
678
633
|
if (typeof subSchema.additionalProperties === 'object') {
|
|
679
634
|
for (const propertyName in subSchema.properties) {
|
|
@@ -725,6 +680,9 @@ async function healJSONSchema(schema) {
|
|
|
725
680
|
pathBasedName += '_';
|
|
726
681
|
}
|
|
727
682
|
}
|
|
683
|
+
if (subSchema.description != null) {
|
|
684
|
+
subSchema.description = subSchema.description.trim();
|
|
685
|
+
}
|
|
728
686
|
}
|
|
729
687
|
return subSchema;
|
|
730
688
|
}, {
|
package/index.mjs
CHANGED
|
@@ -541,48 +541,8 @@ async function getDeduplicatedTitles(schema) {
|
|
|
541
541
|
async function healJSONSchema(schema) {
|
|
542
542
|
const deduplicatedSchema = deduplicateJSONSchema(schema);
|
|
543
543
|
const duplicatedTypeNames = await getDeduplicatedTitles(deduplicatedSchema);
|
|
544
|
-
return visitJSONSchema(deduplicatedSchema,
|
|
544
|
+
return visitJSONSchema(deduplicatedSchema, (subSchema, { path }) => {
|
|
545
545
|
if (typeof subSchema === 'object') {
|
|
546
|
-
// We don't support following properties
|
|
547
|
-
delete subSchema.readOnly;
|
|
548
|
-
delete subSchema.writeOnly;
|
|
549
|
-
const keys = Object.keys(subSchema);
|
|
550
|
-
if (keys.length === 0) {
|
|
551
|
-
subSchema.type = 'object';
|
|
552
|
-
subSchema.additionalProperties = true;
|
|
553
|
-
}
|
|
554
|
-
if (typeof subSchema.additionalProperties === 'object') {
|
|
555
|
-
delete subSchema.additionalProperties.readOnly;
|
|
556
|
-
delete subSchema.additionalProperties.writeOnly;
|
|
557
|
-
if (!subSchema.additionalProperties.type) {
|
|
558
|
-
console.log(path, Object.keys(subSchema.additionalProperties));
|
|
559
|
-
}
|
|
560
|
-
if (Object.keys(subSchema.additionalProperties).length === 0) {
|
|
561
|
-
subSchema.additionalProperties = true;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
if (subSchema.allOf != null && subSchema.allOf.length === 1) {
|
|
565
|
-
const realSubschema = subSchema.allOf[0];
|
|
566
|
-
delete subSchema.allOf;
|
|
567
|
-
return realSubschema;
|
|
568
|
-
}
|
|
569
|
-
if (subSchema.anyOf != null && subSchema.anyOf.length === 1) {
|
|
570
|
-
const realSubschema = subSchema.anyOf[0];
|
|
571
|
-
delete subSchema.anyOf;
|
|
572
|
-
return realSubschema;
|
|
573
|
-
}
|
|
574
|
-
if (subSchema.oneOf != null && subSchema.oneOf.length === 1) {
|
|
575
|
-
const realSubschema = subSchema.oneOf[0];
|
|
576
|
-
delete subSchema.oneOf;
|
|
577
|
-
return realSubschema;
|
|
578
|
-
}
|
|
579
|
-
if (subSchema.description != null) {
|
|
580
|
-
subSchema.description = subSchema.description.trim();
|
|
581
|
-
if (keys.length === 1) {
|
|
582
|
-
subSchema.type = 'object';
|
|
583
|
-
subSchema.additionalProperties = true;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
546
|
// Some JSON Schemas use this broken pattern and refer the type using `items`
|
|
587
547
|
if (subSchema.type === 'object' && subSchema.items) {
|
|
588
548
|
const realSubschema = subSchema.items;
|
|
@@ -595,9 +555,6 @@ async function healJSONSchema(schema) {
|
|
|
595
555
|
if (duplicatedTypeNames.has(subSchema.title)) {
|
|
596
556
|
delete subSchema.title;
|
|
597
557
|
}
|
|
598
|
-
if (typeof subSchema.example === 'object' && !subSchema.type) {
|
|
599
|
-
subSchema.type = 'object';
|
|
600
|
-
}
|
|
601
558
|
// Try to find the type
|
|
602
559
|
if (!subSchema.type) {
|
|
603
560
|
// If required exists without properties
|
|
@@ -653,7 +610,7 @@ async function healJSONSchema(schema) {
|
|
|
653
610
|
}
|
|
654
611
|
}
|
|
655
612
|
// If it is an object type but no properties given while example is available
|
|
656
|
-
if (
|
|
613
|
+
if (subSchema.type === 'object' && !subSchema.properties && subSchema.example) {
|
|
657
614
|
const generatedSchema = toJsonSchema(subSchema.example, {
|
|
658
615
|
required: false,
|
|
659
616
|
objects: {
|
|
@@ -666,9 +623,7 @@ async function healJSONSchema(schema) {
|
|
|
666
623
|
mode: 'first',
|
|
667
624
|
},
|
|
668
625
|
});
|
|
669
|
-
|
|
670
|
-
subSchema.type = asArray(healedGeneratedSchema.type)[0];
|
|
671
|
-
subSchema.properties = healedGeneratedSchema.properties;
|
|
626
|
+
subSchema.properties = generatedSchema.properties;
|
|
672
627
|
// If type for properties is already given, use it
|
|
673
628
|
if (typeof subSchema.additionalProperties === 'object') {
|
|
674
629
|
for (const propertyName in subSchema.properties) {
|
|
@@ -720,6 +675,9 @@ async function healJSONSchema(schema) {
|
|
|
720
675
|
pathBasedName += '_';
|
|
721
676
|
}
|
|
722
677
|
}
|
|
678
|
+
if (subSchema.description != null) {
|
|
679
|
+
subSchema.description = subSchema.description.trim();
|
|
680
|
+
}
|
|
723
681
|
}
|
|
724
682
|
return subSchema;
|
|
725
683
|
}, {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-machete",
|
|
3
|
-
"version": "0.7.12
|
|
3
|
+
"version": "0.7.12",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@graphql-mesh/cross-helpers": "0.1.
|
|
7
|
-
"@graphql-mesh/utils": "0.
|
|
6
|
+
"@graphql-mesh/cross-helpers": "0.1.1",
|
|
7
|
+
"@graphql-mesh/utils": "0.33.6",
|
|
8
8
|
"@graphql-tools/utils": "8.6.9",
|
|
9
9
|
"@json-schema-tools/meta-schema": "1.6.19",
|
|
10
10
|
"cross-undici-fetch": "0.3.0",
|