json-machete 0.10.6-alpha.29892c814 → 0.10.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.
- package/dereferenceObject.d.ts +2 -1
- package/index.js +51 -29
- package/index.mjs +51 -29
- package/package.json +2 -2
package/dereferenceObject.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const resolvePath: (path: string, root: any) => any;
|
|
2
2
|
export declare function getAbsolutePath(path: string, cwd: string): string;
|
|
3
3
|
export declare function getCwd(path: string): string;
|
|
4
|
-
export declare function dereferenceObject<T extends object, TRoot = T>(obj: T, { cwd, externalFileCache, refMap, root, fetchFn: fetch, importFn, logger, headers, }?: {
|
|
4
|
+
export declare function dereferenceObject<T extends object, TRoot = T>(obj: T, { cwd, externalFileCache, refMap, root, fetchFn: fetch, importFn, logger, resolvedObjects, headers, }?: {
|
|
5
5
|
cwd?: string;
|
|
6
6
|
externalFileCache?: Map<string, any>;
|
|
7
7
|
refMap?: Map<string, any>;
|
|
@@ -9,5 +9,6 @@ export declare function dereferenceObject<T extends object, TRoot = T>(obj: T, {
|
|
|
9
9
|
fetchFn?: WindowOrWorkerGlobalScope['fetch'];
|
|
10
10
|
importFn?: (m: string) => any;
|
|
11
11
|
logger?: any;
|
|
12
|
+
resolvedObjects?: WeakSet<any>;
|
|
12
13
|
headers?: Record<string, string>;
|
|
13
14
|
}): Promise<T>;
|
package/index.js
CHANGED
|
@@ -131,7 +131,7 @@ function getCwd(path) {
|
|
|
131
131
|
return isURL(path) ? getCwdForUrl(path) : crossHelpers.path.dirname(path);
|
|
132
132
|
}
|
|
133
133
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
134
|
-
async function dereferenceObject(obj, { cwd = crossHelpers.process.cwd(), externalFileCache = new Map(), refMap = new Map(), root = obj, fetchFn: fetch$1 = fetch.fetch, importFn = utils$1.defaultImportFn, logger = new utils$1.DefaultLogger('dereferenceObject'), headers, } = {}) {
|
|
134
|
+
async function dereferenceObject(obj, { cwd = crossHelpers.process.cwd(), externalFileCache = new Map(), refMap = new Map(), root = obj, fetchFn: fetch$1 = fetch.fetch, importFn = utils$1.defaultImportFn, logger = new utils$1.DefaultLogger('dereferenceObject'), resolvedObjects = new WeakSet(), headers, } = {}) {
|
|
135
135
|
var _a;
|
|
136
136
|
if (obj != null && typeof obj === 'object') {
|
|
137
137
|
if (isRefObject(obj)) {
|
|
@@ -212,8 +212,10 @@ async function dereferenceObject(obj, { cwd = crossHelpers.process.cwd(), extern
|
|
|
212
212
|
logger,
|
|
213
213
|
headers,
|
|
214
214
|
root: externalFile,
|
|
215
|
+
resolvedObjects,
|
|
215
216
|
});
|
|
216
217
|
refMap.set($ref, result);
|
|
218
|
+
resolvedObjects.add(result);
|
|
217
219
|
if (result && !result.$resolvedRef) {
|
|
218
220
|
result.$resolvedRef = refPath;
|
|
219
221
|
}
|
|
@@ -224,12 +226,15 @@ async function dereferenceObject(obj, { cwd = crossHelpers.process.cwd(), extern
|
|
|
224
226
|
}
|
|
225
227
|
else {
|
|
226
228
|
const resolvedObj = resolvePath(refPath, root);
|
|
227
|
-
if (
|
|
229
|
+
if (resolvedObjects.has(resolvedObj)) {
|
|
228
230
|
refMap.set($ref, resolvedObj);
|
|
231
|
+
return resolvedObj;
|
|
229
232
|
}
|
|
233
|
+
/*
|
|
230
234
|
if (resolvedObj && !resolvedObj.$resolvedRef) {
|
|
231
|
-
|
|
235
|
+
resolvedObj.$resolvedRef = refPath;
|
|
232
236
|
}
|
|
237
|
+
*/
|
|
233
238
|
const result = await dereferenceObject(resolvedObj, {
|
|
234
239
|
cwd,
|
|
235
240
|
externalFileCache,
|
|
@@ -239,9 +244,14 @@ async function dereferenceObject(obj, { cwd = crossHelpers.process.cwd(), extern
|
|
|
239
244
|
importFn,
|
|
240
245
|
logger,
|
|
241
246
|
headers,
|
|
247
|
+
resolvedObjects,
|
|
242
248
|
});
|
|
249
|
+
if (!result) {
|
|
250
|
+
return obj;
|
|
251
|
+
}
|
|
252
|
+
resolvedObjects.add(result);
|
|
243
253
|
refMap.set($ref, result);
|
|
244
|
-
if (
|
|
254
|
+
if (!result.$resolvedRef) {
|
|
245
255
|
result.$resolvedRef = refPath;
|
|
246
256
|
}
|
|
247
257
|
return result;
|
|
@@ -249,17 +259,21 @@ async function dereferenceObject(obj, { cwd = crossHelpers.process.cwd(), extern
|
|
|
249
259
|
}
|
|
250
260
|
}
|
|
251
261
|
else {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
obj[key]
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
262
|
+
if (!resolvedObjects.has(obj)) {
|
|
263
|
+
resolvedObjects.add(obj);
|
|
264
|
+
for (const key in obj) {
|
|
265
|
+
const val = obj[key];
|
|
266
|
+
if (typeof val === 'object') {
|
|
267
|
+
obj[key] = await dereferenceObject(val, {
|
|
268
|
+
cwd,
|
|
269
|
+
externalFileCache,
|
|
270
|
+
refMap,
|
|
271
|
+
root,
|
|
272
|
+
fetchFn: fetch$1,
|
|
273
|
+
headers,
|
|
274
|
+
resolvedObjects,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
263
277
|
}
|
|
264
278
|
}
|
|
265
279
|
}
|
|
@@ -523,12 +537,12 @@ async function healJSONSchema(schema, options = {}) {
|
|
|
523
537
|
subSchema.additionalProperties = true;
|
|
524
538
|
}
|
|
525
539
|
}
|
|
526
|
-
if (subSchema.allOf != null && subSchema.allOf.length === 1) {
|
|
540
|
+
if (subSchema.allOf != null && subSchema.allOf.length === 1 && !subSchema.properties) {
|
|
527
541
|
const realSubschema = subSchema.allOf[0];
|
|
528
542
|
delete subSchema.allOf;
|
|
529
543
|
return realSubschema;
|
|
530
544
|
}
|
|
531
|
-
if (subSchema.anyOf != null && subSchema.anyOf.length === 1) {
|
|
545
|
+
if (subSchema.anyOf != null && subSchema.anyOf.length === 1 && !subSchema.properties) {
|
|
532
546
|
const realSubschema = subSchema.anyOf[0];
|
|
533
547
|
delete subSchema.anyOf;
|
|
534
548
|
return realSubschema;
|
|
@@ -589,11 +603,15 @@ async function healJSONSchema(schema, options = {}) {
|
|
|
589
603
|
}
|
|
590
604
|
}
|
|
591
605
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
606
|
+
switch (subSchema.format) {
|
|
607
|
+
case 'int64':
|
|
608
|
+
case 'int32':
|
|
609
|
+
subSchema.type = 'integer';
|
|
610
|
+
break;
|
|
611
|
+
default:
|
|
612
|
+
if (subSchema.format != null) {
|
|
613
|
+
subSchema.type = 'string';
|
|
614
|
+
}
|
|
597
615
|
}
|
|
598
616
|
}
|
|
599
617
|
if (subSchema.type === 'string' && !subSchema.format && (subSchema.examples || subSchema.example)) {
|
|
@@ -666,22 +684,26 @@ async function healJSONSchema(schema, options = {}) {
|
|
|
666
684
|
subSchema.title = pathBasedName;
|
|
667
685
|
// Otherwise use the format name
|
|
668
686
|
}
|
|
669
|
-
else if (subSchema.format) {
|
|
670
|
-
subSchema.title = subSchema.format;
|
|
671
|
-
}
|
|
672
687
|
break;
|
|
673
688
|
case 'number':
|
|
674
689
|
case 'integer':
|
|
675
|
-
if (subSchema.enum) {
|
|
690
|
+
if (subSchema.enum || subSchema.pattern) {
|
|
676
691
|
subSchema.title = pathBasedName;
|
|
677
692
|
// Otherwise use the format name
|
|
678
693
|
}
|
|
679
|
-
else if (subSchema.format) {
|
|
680
|
-
subSchema.title = subSchema.format;
|
|
681
|
-
}
|
|
682
694
|
break;
|
|
683
695
|
case 'array':
|
|
684
696
|
break;
|
|
697
|
+
case 'boolean':
|
|
698
|
+
// pattern is unnecessary for boolean
|
|
699
|
+
if (subSchema.pattern) {
|
|
700
|
+
delete subSchema.pattern;
|
|
701
|
+
}
|
|
702
|
+
// enum is unnecessary for boolean
|
|
703
|
+
if (subSchema.enum) {
|
|
704
|
+
delete subSchema.enum;
|
|
705
|
+
}
|
|
706
|
+
break;
|
|
685
707
|
default:
|
|
686
708
|
subSchema.title = subSchema.title || pathBasedName;
|
|
687
709
|
}
|
package/index.mjs
CHANGED
|
@@ -125,7 +125,7 @@ function getCwd(path$1) {
|
|
|
125
125
|
return isURL(path$1) ? getCwdForUrl(path$1) : path.dirname(path$1);
|
|
126
126
|
}
|
|
127
127
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
128
|
-
async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache = new Map(), refMap = new Map(), root = obj, fetchFn: fetch$1 = fetch, importFn = defaultImportFn, logger = new DefaultLogger('dereferenceObject'), headers, } = {}) {
|
|
128
|
+
async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache = new Map(), refMap = new Map(), root = obj, fetchFn: fetch$1 = fetch, importFn = defaultImportFn, logger = new DefaultLogger('dereferenceObject'), resolvedObjects = new WeakSet(), headers, } = {}) {
|
|
129
129
|
var _a;
|
|
130
130
|
if (obj != null && typeof obj === 'object') {
|
|
131
131
|
if (isRefObject(obj)) {
|
|
@@ -206,8 +206,10 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
|
|
|
206
206
|
logger,
|
|
207
207
|
headers,
|
|
208
208
|
root: externalFile,
|
|
209
|
+
resolvedObjects,
|
|
209
210
|
});
|
|
210
211
|
refMap.set($ref, result);
|
|
212
|
+
resolvedObjects.add(result);
|
|
211
213
|
if (result && !result.$resolvedRef) {
|
|
212
214
|
result.$resolvedRef = refPath;
|
|
213
215
|
}
|
|
@@ -218,12 +220,15 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
|
|
|
218
220
|
}
|
|
219
221
|
else {
|
|
220
222
|
const resolvedObj = resolvePath(refPath, root);
|
|
221
|
-
if (
|
|
223
|
+
if (resolvedObjects.has(resolvedObj)) {
|
|
222
224
|
refMap.set($ref, resolvedObj);
|
|
225
|
+
return resolvedObj;
|
|
223
226
|
}
|
|
227
|
+
/*
|
|
224
228
|
if (resolvedObj && !resolvedObj.$resolvedRef) {
|
|
225
|
-
|
|
229
|
+
resolvedObj.$resolvedRef = refPath;
|
|
226
230
|
}
|
|
231
|
+
*/
|
|
227
232
|
const result = await dereferenceObject(resolvedObj, {
|
|
228
233
|
cwd,
|
|
229
234
|
externalFileCache,
|
|
@@ -233,9 +238,14 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
|
|
|
233
238
|
importFn,
|
|
234
239
|
logger,
|
|
235
240
|
headers,
|
|
241
|
+
resolvedObjects,
|
|
236
242
|
});
|
|
243
|
+
if (!result) {
|
|
244
|
+
return obj;
|
|
245
|
+
}
|
|
246
|
+
resolvedObjects.add(result);
|
|
237
247
|
refMap.set($ref, result);
|
|
238
|
-
if (
|
|
248
|
+
if (!result.$resolvedRef) {
|
|
239
249
|
result.$resolvedRef = refPath;
|
|
240
250
|
}
|
|
241
251
|
return result;
|
|
@@ -243,17 +253,21 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
|
|
|
243
253
|
}
|
|
244
254
|
}
|
|
245
255
|
else {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
obj[key]
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
256
|
+
if (!resolvedObjects.has(obj)) {
|
|
257
|
+
resolvedObjects.add(obj);
|
|
258
|
+
for (const key in obj) {
|
|
259
|
+
const val = obj[key];
|
|
260
|
+
if (typeof val === 'object') {
|
|
261
|
+
obj[key] = await dereferenceObject(val, {
|
|
262
|
+
cwd,
|
|
263
|
+
externalFileCache,
|
|
264
|
+
refMap,
|
|
265
|
+
root,
|
|
266
|
+
fetchFn: fetch$1,
|
|
267
|
+
headers,
|
|
268
|
+
resolvedObjects,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
257
271
|
}
|
|
258
272
|
}
|
|
259
273
|
}
|
|
@@ -517,12 +531,12 @@ async function healJSONSchema(schema, options = {}) {
|
|
|
517
531
|
subSchema.additionalProperties = true;
|
|
518
532
|
}
|
|
519
533
|
}
|
|
520
|
-
if (subSchema.allOf != null && subSchema.allOf.length === 1) {
|
|
534
|
+
if (subSchema.allOf != null && subSchema.allOf.length === 1 && !subSchema.properties) {
|
|
521
535
|
const realSubschema = subSchema.allOf[0];
|
|
522
536
|
delete subSchema.allOf;
|
|
523
537
|
return realSubschema;
|
|
524
538
|
}
|
|
525
|
-
if (subSchema.anyOf != null && subSchema.anyOf.length === 1) {
|
|
539
|
+
if (subSchema.anyOf != null && subSchema.anyOf.length === 1 && !subSchema.properties) {
|
|
526
540
|
const realSubschema = subSchema.anyOf[0];
|
|
527
541
|
delete subSchema.anyOf;
|
|
528
542
|
return realSubschema;
|
|
@@ -583,11 +597,15 @@ async function healJSONSchema(schema, options = {}) {
|
|
|
583
597
|
}
|
|
584
598
|
}
|
|
585
599
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
600
|
+
switch (subSchema.format) {
|
|
601
|
+
case 'int64':
|
|
602
|
+
case 'int32':
|
|
603
|
+
subSchema.type = 'integer';
|
|
604
|
+
break;
|
|
605
|
+
default:
|
|
606
|
+
if (subSchema.format != null) {
|
|
607
|
+
subSchema.type = 'string';
|
|
608
|
+
}
|
|
591
609
|
}
|
|
592
610
|
}
|
|
593
611
|
if (subSchema.type === 'string' && !subSchema.format && (subSchema.examples || subSchema.example)) {
|
|
@@ -660,22 +678,26 @@ async function healJSONSchema(schema, options = {}) {
|
|
|
660
678
|
subSchema.title = pathBasedName;
|
|
661
679
|
// Otherwise use the format name
|
|
662
680
|
}
|
|
663
|
-
else if (subSchema.format) {
|
|
664
|
-
subSchema.title = subSchema.format;
|
|
665
|
-
}
|
|
666
681
|
break;
|
|
667
682
|
case 'number':
|
|
668
683
|
case 'integer':
|
|
669
|
-
if (subSchema.enum) {
|
|
684
|
+
if (subSchema.enum || subSchema.pattern) {
|
|
670
685
|
subSchema.title = pathBasedName;
|
|
671
686
|
// Otherwise use the format name
|
|
672
687
|
}
|
|
673
|
-
else if (subSchema.format) {
|
|
674
|
-
subSchema.title = subSchema.format;
|
|
675
|
-
}
|
|
676
688
|
break;
|
|
677
689
|
case 'array':
|
|
678
690
|
break;
|
|
691
|
+
case 'boolean':
|
|
692
|
+
// pattern is unnecessary for boolean
|
|
693
|
+
if (subSchema.pattern) {
|
|
694
|
+
delete subSchema.pattern;
|
|
695
|
+
}
|
|
696
|
+
// enum is unnecessary for boolean
|
|
697
|
+
if (subSchema.enum) {
|
|
698
|
+
delete subSchema.enum;
|
|
699
|
+
}
|
|
700
|
+
break;
|
|
679
701
|
default:
|
|
680
702
|
subSchema.title = subSchema.title || pathBasedName;
|
|
681
703
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-machete",
|
|
3
|
-
"version": "0.10.6
|
|
3
|
+
"version": "0.10.6",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@graphql-mesh/cross-helpers": "0.2.0",
|
|
7
|
-
"@graphql-mesh/utils": "0.37.
|
|
7
|
+
"@graphql-mesh/utils": "0.37.7",
|
|
8
8
|
"@graphql-tools/utils": "8.9.0",
|
|
9
9
|
"@json-schema-tools/meta-schema": "1.6.19",
|
|
10
10
|
"@whatwg-node/fetch": "^0.2.7",
|