@json-schema-tools/reference-resolver
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -156,2 +156,12 @@ "use strict"; | ||
}; | ||
var resolvePointer = function (ref, root) { | ||
try { | ||
var withoutHash = ref.replace("#", ""); | ||
var pointer = json_pointer_1.default.parse(withoutHash); | ||
return pointer.eval(root); | ||
} | ||
catch (e) { | ||
throw new InvalidJsonPointerRefError({ $ref: ref }); | ||
} | ||
}; | ||
/** | ||
@@ -162,3 +172,3 @@ * Given a $ref string, it will return the underlying pointed-to value. | ||
var resolveReference = function (ref, root) { return __awaiter(void 0, void 0, void 0, function () { | ||
var withoutHash, pointer, hashFragmentSplit, hashFragment, hashlessRef, fileContents, reffedSchema, pointer, result, e_1, pointer; | ||
var hashFragmentSplit, hashFragment, hashlessRef, fileContents, reffedSchema, result, e_1; | ||
return __generator(this, function (_a) { | ||
@@ -168,10 +178,3 @@ switch (_a.label) { | ||
if (ref[0] === "#") { | ||
withoutHash = ref.replace("#", ""); | ||
try { | ||
pointer = json_pointer_1.default.parse(withoutHash); | ||
return [2 /*return*/, Promise.resolve(pointer.eval(root))]; | ||
} | ||
catch (e) { | ||
throw new InvalidJsonPointerRefError({ $ref: ref }); | ||
} | ||
return [2 /*return*/, Promise.resolve(resolvePointer(ref, root))]; | ||
} | ||
@@ -182,6 +185,3 @@ hashFragmentSplit = ref.split("#"); | ||
} | ||
hashlessRef = ref; | ||
if (hashFragment) { | ||
hashlessRef = ref.replace("#" + hashFragment, ""); | ||
} | ||
hashlessRef = hashFragmentSplit[0]; | ||
return [4 /*yield*/, fileExistsAndReadable(hashlessRef)]; | ||
@@ -201,9 +201,3 @@ case 1: | ||
if (hashFragment) { | ||
try { | ||
pointer = json_pointer_1.default.parse(hashFragment); | ||
return [2 /*return*/, Promise.resolve(pointer.eval(reffedSchema))]; | ||
} | ||
catch (e) { | ||
throw new InvalidJsonPointerRefError({ $ref: ref }); | ||
} | ||
reffedSchema = resolvePointer(hashFragment, reffedSchema); | ||
} | ||
@@ -218,3 +212,3 @@ return [2 /*return*/, reffedSchema]; | ||
_a.trys.push([4, 6, , 7]); | ||
return [4 /*yield*/, fetch(ref).then(function (r) { return r.json(); })]; | ||
return [4 /*yield*/, fetch(hashlessRef).then(function (r) { return r.json(); })]; | ||
case 5: | ||
@@ -228,9 +222,3 @@ result = _a.sent(); | ||
if (hashFragment) { | ||
try { | ||
pointer = json_pointer_1.default.parse(hashFragment); | ||
return [2 /*return*/, Promise.resolve(pointer.eval(result))]; | ||
} | ||
catch (e) { | ||
throw new InvalidJsonPointerRefError({ $ref: ref }); | ||
} | ||
result = resolvePointer(hashFragment, result); | ||
} | ||
@@ -237,0 +225,0 @@ return [2 /*return*/, result]; |
@@ -0,1 +1,10 @@ | ||
## [1.1.1](https://github.com/json-schema-tools/reference-resolver/compare/1.1.0...1.1.1) (2020-11-03) | ||
### Bug Fixes | ||
* refactor code into shared method ([794a8ce](https://github.com/json-schema-tools/reference-resolver/commit/794a8ce0bb22519af0c04992df74e2da7cabc09c)) | ||
* return a promise once again ([772302d](https://github.com/json-schema-tools/reference-resolver/commit/772302da07e808f56053be7cde679e6aa52bd8a9)) | ||
* use hashless ref for urls ([f278761](https://github.com/json-schema-tools/reference-resolver/commit/f278761c9c934a38de415c9756f2c40b29c8d1cd)) | ||
# [1.1.0](https://github.com/json-schema-tools/reference-resolver/compare/1.0.7...1.1.0) (2020-10-28) | ||
@@ -2,0 +11,0 @@ |
{ | ||
"name": "@json-schema-tools/reference-resolver", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38410
339