@apidevtools/json-schema-ref-parser 15.3.6 → 15.4.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.
- package/dist/lib/bundle.d.ts +1 -0
- package/dist/lib/bundle.js +6 -2
- package/lib/bundle.ts +7 -2
- package/package.json +1 -1
package/dist/lib/bundle.d.ts
CHANGED
package/dist/lib/bundle.js
CHANGED
|
@@ -119,6 +119,7 @@ function inventory$Ref($refParent, $refKey, path, scopeBase, dynamicIdScope, pat
|
|
|
119
119
|
const file = url.stripHash(pointer.path);
|
|
120
120
|
const hash = url.getHash(pointer.path);
|
|
121
121
|
const external = file !== $refs._root$Ref.path && !$refs._aliases[file];
|
|
122
|
+
const nestedResource = Boolean($refs._aliases[file]) && pointer.$ref.value !== $refs._root$Ref.value;
|
|
122
123
|
const extended = $Ref.isExtended$Ref($ref);
|
|
123
124
|
indirections += pointer.indirections;
|
|
124
125
|
const existingEntry = findInInventory(inventory, $refParent, $refKey);
|
|
@@ -143,6 +144,7 @@ function inventory$Ref($refParent, $refKey, path, scopeBase, dynamicIdScope, pat
|
|
|
143
144
|
circular: pointer.circular, // Is this $ref pointer DIRECTLY circular? (i.e. it references itself)
|
|
144
145
|
extended, // Does this $ref extend its resolved value? (i.e. it has extra properties, in addition to "$ref")
|
|
145
146
|
external, // Does this $ref pointer point to a file other than the main JSON Schema file?
|
|
147
|
+
nestedResource, // Does this $ref resolve to an embedded schema resource with its own $id?
|
|
146
148
|
indirections, // The number of indirect references that were traversed to resolve the value
|
|
147
149
|
});
|
|
148
150
|
// Recursively crawl the resolved value
|
|
@@ -221,8 +223,10 @@ function remap(inventory, options, rootId) {
|
|
|
221
223
|
if (!entry.external) {
|
|
222
224
|
// This $ref already resolves to the main JSON Schema file.
|
|
223
225
|
// When optimizeInternalRefs is false, preserve the original internal ref path
|
|
224
|
-
// instead of rewriting it to the fully resolved hash.
|
|
225
|
-
|
|
226
|
+
// instead of rewriting it to the fully resolved hash. References to nested
|
|
227
|
+
// resources must also retain their resource URI so that "#" does not point
|
|
228
|
+
// at the document root instead.
|
|
229
|
+
if (bundleOpts.optimizeInternalRefs !== false && !entry.nestedResource) {
|
|
226
230
|
entry.$ref.$ref = entry.hash;
|
|
227
231
|
}
|
|
228
232
|
}
|
package/lib/bundle.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface InventoryEntry {
|
|
|
20
20
|
circular: any;
|
|
21
21
|
extended: any;
|
|
22
22
|
external: any;
|
|
23
|
+
nestedResource: boolean;
|
|
23
24
|
indirections: any;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
@@ -194,6 +195,7 @@ function inventory$Ref<S extends object = JSONSchema, O extends ParserOptions<S>
|
|
|
194
195
|
const file = url.stripHash(pointer.path);
|
|
195
196
|
const hash = url.getHash(pointer.path);
|
|
196
197
|
const external = file !== $refs._root$Ref.path && !$refs._aliases[file];
|
|
198
|
+
const nestedResource = Boolean($refs._aliases[file]) && pointer.$ref.value !== $refs._root$Ref.value;
|
|
197
199
|
const extended = $Ref.isExtended$Ref($ref);
|
|
198
200
|
indirections += pointer.indirections;
|
|
199
201
|
|
|
@@ -219,6 +221,7 @@ function inventory$Ref<S extends object = JSONSchema, O extends ParserOptions<S>
|
|
|
219
221
|
circular: pointer.circular, // Is this $ref pointer DIRECTLY circular? (i.e. it references itself)
|
|
220
222
|
extended, // Does this $ref extend its resolved value? (i.e. it has extra properties, in addition to "$ref")
|
|
221
223
|
external, // Does this $ref pointer point to a file other than the main JSON Schema file?
|
|
224
|
+
nestedResource, // Does this $ref resolve to an embedded schema resource with its own $id?
|
|
222
225
|
indirections, // The number of indirect references that were traversed to resolve the value
|
|
223
226
|
});
|
|
224
227
|
|
|
@@ -316,8 +319,10 @@ function remap<S extends object = JSONSchema, O extends ParserOptions<S> = Parse
|
|
|
316
319
|
if (!entry.external) {
|
|
317
320
|
// This $ref already resolves to the main JSON Schema file.
|
|
318
321
|
// When optimizeInternalRefs is false, preserve the original internal ref path
|
|
319
|
-
// instead of rewriting it to the fully resolved hash.
|
|
320
|
-
|
|
322
|
+
// instead of rewriting it to the fully resolved hash. References to nested
|
|
323
|
+
// resources must also retain their resource URI so that "#" does not point
|
|
324
|
+
// at the document root instead.
|
|
325
|
+
if (bundleOpts.optimizeInternalRefs !== false && !entry.nestedResource) {
|
|
321
326
|
entry.$ref.$ref = entry.hash;
|
|
322
327
|
}
|
|
323
328
|
} else if (entry.file === file && entry.hash === hash) {
|