From a95cf50fdf16c864cc1c18d2021d9ce3ec35f5de Mon Sep 17 00:00:00 2001 From: James Messinger Date: Sat, 17 Mar 2018 15:59:07 +0800 Subject: [PATCH] Set the `pathType` of the root schema file, so its path is correctly formatted by `$refs.paths()` and `$refs.values()` --- lib/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index d79b24ce..cb938081 100644 --- a/lib/index.js +++ b/lib/index.js @@ -85,8 +85,10 @@ $RefParser.prototype.parse = function (path, schema, options, callback) { // So we're being generous here and doing the conversion automatically. // This is not intended to be a 100% bulletproof solution. // If it doesn't work for your use-case, then use a URL instead. + var pathType = 'http'; if (url.isFileSystemPath(args.path)) { args.path = url.fromFileSystemPath(args.path); + pathType = 'file'; } // Resolve the absolute path of the schema @@ -95,7 +97,9 @@ $RefParser.prototype.parse = function (path, schema, options, callback) { if (args.schema && typeof args.schema === 'object') { // A schema object was passed-in. // So immediately add a new $Ref with the schema object as its value - this.$refs._add(args.path, args.schema); + var $ref = this.$refs._add(args.path); + $ref.value = args.schema; + $ref.pathType = pathType; promise = Promise.resolve(args.schema); } else {