diff --git a/lib/index.js b/lib/index.js index cb938081..102bef1a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -91,11 +91,16 @@ $RefParser.prototype.parse = function (path, schema, options, callback) { pathType = 'file'; } - // Resolve the absolute path of the schema - args.path = url.resolve(url.cwd(), args.path); if (args.schema && typeof args.schema === 'object') { // A schema object was passed-in. + if (args.schema.$id) { // if an id is passed it will use the base uri for the path of the object + var u = url.parse(args.schema.$id); + args.path = u.protocol + '//' + u.host + '/#'; + } + else { + args.path = url.resolve(url.cwd(), args.path); + } // So immediately add a new $Ref with the schema object as its value var $ref = this.$refs._add(args.path); $ref.value = args.schema; @@ -104,6 +109,8 @@ $RefParser.prototype.parse = function (path, schema, options, callback) { } else { // Parse the schema file/url + // Resolve the absolute path of the schema + args.path = url.resolve(url.cwd(), args.path); promise = parse(args.path, this.$refs, args.options); }