From 7438237d11452b4570ffe21015250d9defc79b24 Mon Sep 17 00:00:00 2001 From: James Messinger Date: Thu, 31 Dec 2015 16:50:28 -0600 Subject: [PATCH] "release v2.1.0" --- dist/ref-parser.js | 2 +- dist/ref-parser.js.map | 2 +- dist/ref-parser.min.js | 2 +- dist/ref-parser.min.js.map | 2 +- lib/bundle.js | 2 +- package.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/ref-parser.js b/dist/ref-parser.js index 10b923ad..82a85b2e 100644 --- a/dist/ref-parser.js +++ b/dist/ref-parser.js @@ -1,6 +1,6 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.$RefParser = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 1) {\n // The current value has additional properties (other than \"$ref\"),\n // so merge the resolved value rather than completely replacing the reference\n var merged = {};\n Object.keys(currentValue).forEach(function(key) {\n if (key !== '$ref') {\n merged[key] = currentValue[key];\n }\n });\n Object.keys(resolvedValue).forEach(function(key) {\n if (!(key in merged)) {\n merged[key] = resolvedValue[key];\n }\n });\n return merged;\n }\n else {\n // Completely replace the original reference with the resolved value\n return resolvedValue;\n }\n}\n\n/**\n * Called when a circular reference is found.\n * It sets the {@link $Refs#circular} flag, and throws an error if options.$refs.circular is false.\n *\n * @param {string} keyPath - The JSON Reference path of the circular reference\n * @param {$Refs} $refs\n * @param {$RefParserOptions} options\n * @returns {boolean} - always returns true, to indicate that a circular reference was found\n */\nfunction foundCircularReference(keyPath, $refs, options) {\n $refs.circular = true;\n if (!options.$refs.circular) {\n throw ono.reference('Circular $ref pointer found at %s', keyPath);\n }\n return true;\n}\n", "'use strict';\n\nvar http = require('http'),\n https = require('https'),\n url = require('url'),\n util = require('./util'),\n Promise = require('./promise'),\n ono = require('ono');\n\nmodule.exports = download;\n\n/**\n * Downloads the given file.\n *\n * @param {Url|string} u - The url to download (can be a parsed {@link Url} object)\n * @param {$RefParserOptions} options\n * @param {number} [redirects] - The redirect URLs that have already been followed\n *\n * @returns {Promise}\n * The promise resolves with the raw downloaded data, or rejects if there is an HTTP error.\n */\nfunction download(u, options, redirects) {\n return new Promise(function(resolve, reject) {\n u = url.parse(u);\n redirects = redirects || [];\n redirects.push(u.href);\n\n get(u, options)\n .then(function(res) {\n if (res.statusCode >= 400) {\n throw ono({status: res.statusCode}, 'HTTP ERROR %d', res.statusCode);\n }\n else if (res.statusCode >= 300) {\n if (redirects.length > options.http.redirects) {\n reject(ono({status: res.statusCode}, 'Error downloading %s. \\nToo many redirects: \\n %s',\n redirects[0], redirects.join(' \\n ')));\n }\n else if (!res.headers.location) {\n throw ono({status: res.statusCode}, 'HTTP %d redirect with no location header', res.statusCode);\n }\n else {\n util.debug('HTTP %d redirect %s -> %s', res.statusCode, u.href, res.headers.location);\n var redirectTo = url.resolve(u, res.headers.location);\n download(redirectTo, options, redirects).then(resolve, reject);\n }\n }\n else if (res.statusCode === 204 && !options.allow.empty) {\n throw ono({status: 204}, 'HTTP 204 (No Content)');\n }\n else {\n resolve(res.body || new Buffer(0));\n }\n })\n .catch(function(err) {\n reject(ono(err, 'Error downloading', u.href));\n });\n });\n}\n\n/**\n * Sends an HTTP GET request.\n *\n * @param {Url} u - A parsed {@link Url} object\n * @param {$RefParserOptions} options\n *\n * @returns {Promise}\n * The promise resolves with the HTTP Response object.\n */\nfunction get(u, options) {\n return new Promise(function(resolve, reject) {\n util.debug('GET', u.href);\n\n var protocol = u.protocol === 'https:' ? https : http;\n var req = protocol.get({\n hostname: u.hostname,\n port: u.port,\n path: u.path,\n auth: u.auth,\n headers: options.http.headers,\n withCredentials: options.http.withCredentials\n });\n\n if (typeof req.setTimeout === 'function') {\n req.setTimeout(options.http.timeout);\n }\n\n req.on('timeout', function() {\n req.abort();\n });\n\n req.on('error', reject);\n\n req.once('response', function(res) {\n res.body = new Buffer(0);\n\n res.on('data', function(data) {\n res.body = Buffer.concat([res.body, new Buffer(data)]);\n });\n\n res.on('error', reject);\n\n res.on('end', function() {\n resolve(res);\n });\n });\n });\n}\n", "'use strict';\n\nvar Promise = require('./promise'),\n Options = require('./options'),\n $Refs = require('./refs'),\n $Ref = require('./ref'),\n read = require('./read'),\n resolve = require('./resolve'),\n bundle = require('./bundle'),\n dereference = require('./dereference'),\n util = require('./util'),\n url = require('url'),\n maybe = require('call-me-maybe'),\n ono = require('ono');\n\nmodule.exports = $RefParser;\nmodule.exports.YAML = require('./yaml');\n\n/**\n * This class parses a JSON schema, builds a map of its JSON references and their resolved values,\n * and provides methods for traversing, manipulating, and dereferencing those references.\n *\n * @constructor\n */\nfunction $RefParser() {\n /**\n * The parsed (and possibly dereferenced) JSON schema object\n *\n * @type {object}\n * @readonly\n */\n this.schema = null;\n\n /**\n * The resolved JSON references\n *\n * @type {$Refs}\n */\n this.$refs = new $Refs();\n\n /**\n * The file path or URL of the main JSON schema file.\n * This will be empty if the schema was passed as an object rather than a path.\n *\n * @type {string}\n * @protected\n */\n this._basePath = '';\n}\n\n/**\n * Parses the given JSON schema.\n * This method does not resolve any JSON references.\n * It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed\n * @param {function} [callback] - An error-first callback. The second parameter is the parsed JSON schema object.\n * @returns {Promise} - The returned promise resolves with the parsed JSON schema object.\n */\n$RefParser.parse = function(schema, options, callback) {\n var Class = this; // eslint-disable-line consistent-this\n return new Class().parse(schema, options, callback);\n};\n\n/**\n * Parses the given JSON schema.\n * This method does not resolve any JSON references.\n * It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed\n * @param {function} [callback] - An error-first callback. The second parameter is the parsed JSON schema object.\n * @returns {Promise} - The returned promise resolves with the parsed JSON schema object.\n */\n$RefParser.prototype.parse = function(schema, options, callback) {\n var args = normalizeArgs(arguments);\n\n if (args.schema && typeof args.schema === 'object') {\n // The schema is an object, not a path/url\n this.schema = args.schema;\n this._basePath = '';\n var $ref = new $Ref(this.$refs, this._basePath);\n $ref.setValue(this.schema, args.options);\n\n return maybe(args.callback, Promise.resolve(this.schema));\n }\n\n if (!args.schema || typeof args.schema !== 'string') {\n var err = ono('Expected a file path, URL, or object. Got %s', args.schema);\n return maybe(args.callback, Promise.reject(err));\n }\n\n var me = this;\n\n // Resolve the absolute path of the schema\n args.schema = util.path.localPathToUrl(args.schema);\n args.schema = url.resolve(util.path.cwd(), args.schema);\n this._basePath = util.path.stripHash(args.schema);\n\n // Read the schema file/url\n return read(args.schema, this.$refs, args.options)\n .then(function(cached$Ref) {\n var value = cached$Ref.$ref.value;\n if (!value || typeof value !== 'object' || value instanceof Buffer) {\n throw ono.syntax('\"%s\" is not a valid JSON Schema', me._basePath);\n }\n else {\n me.schema = value;\n return maybe(args.callback, Promise.resolve(me.schema));\n }\n })\n .catch(function(e) {\n return maybe(args.callback, Promise.reject(e));\n });\n};\n\n/**\n * Parses the given JSON schema and resolves any JSON references, including references in\n * externally-referenced files.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed and resolved\n * @param {function} [callback]\n * - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references\n *\n * @returns {Promise}\n * The returned promise resolves with a {@link $Refs} object containing the resolved JSON references\n */\n$RefParser.resolve = function(schema, options, callback) {\n var Class = this; // eslint-disable-line consistent-this\n return new Class().resolve(schema, options, callback);\n};\n\n/**\n * Parses the given JSON schema and resolves any JSON references, including references in\n * externally-referenced files.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed and resolved\n * @param {function} [callback]\n * - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references\n *\n * @returns {Promise}\n * The returned promise resolves with a {@link $Refs} object containing the resolved JSON references\n */\n$RefParser.prototype.resolve = function(schema, options, callback) {\n var me = this;\n var args = normalizeArgs(arguments);\n\n return this.parse(args.schema, args.options)\n .then(function() {\n return resolve(me, args.options);\n })\n .then(function() {\n return maybe(args.callback, Promise.resolve(me.$refs));\n })\n .catch(function(err) {\n return maybe(args.callback, Promise.reject(err));\n });\n};\n\n/**\n * Parses the given JSON schema, resolves any JSON references, and bundles all external references\n * into the main JSON schema. This produces a JSON schema that only has *internal* references,\n * not any *external* references.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced\n * @param {function} [callback] - An error-first callback. The second parameter is the bundled JSON schema object\n * @returns {Promise} - The returned promise resolves with the bundled JSON schema object.\n */\n$RefParser.bundle = function(schema, options, callback) {\n var Class = this; // eslint-disable-line consistent-this\n return new Class().bundle(schema, options, callback);\n};\n\n/**\n * Parses the given JSON schema, resolves any JSON references, and bundles all external references\n * into the main JSON schema. This produces a JSON schema that only has *internal* references,\n * not any *external* references.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced\n * @param {function} [callback] - An error-first callback. The second parameter is the bundled JSON schema object\n * @returns {Promise} - The returned promise resolves with the bundled JSON schema object.\n */\n$RefParser.prototype.bundle = function(schema, options, callback) {\n var me = this;\n var args = normalizeArgs(arguments);\n\n return this.resolve(args.schema, args.options)\n .then(function() {\n bundle(me, args.options);\n return maybe(args.callback, Promise.resolve(me.schema));\n })\n .catch(function(err) {\n return maybe(args.callback, Promise.reject(err));\n });\n};\n\n/**\n * Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.\n * That is, all JSON references are replaced with their resolved values.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced\n * @param {function} [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object\n * @returns {Promise} - The returned promise resolves with the dereferenced JSON schema object.\n */\n$RefParser.dereference = function(schema, options, callback) {\n var Class = this; // eslint-disable-line consistent-this\n return new Class().dereference(schema, options, callback);\n};\n\n/**\n * Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.\n * That is, all JSON references are replaced with their resolved values.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced\n * @param {function} [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object\n * @returns {Promise} - The returned promise resolves with the dereferenced JSON schema object.\n */\n$RefParser.prototype.dereference = function(schema, options, callback) {\n var me = this;\n var args = normalizeArgs(arguments);\n\n return this.resolve(args.schema, args.options)\n .then(function() {\n dereference(me, args.options);\n return maybe(args.callback, Promise.resolve(me.schema));\n })\n .catch(function(err) {\n return maybe(args.callback, Promise.reject(err));\n });\n};\n\n/**\n * Normalizes the given arguments, accounting for optional args.\n *\n * @param {Arguments} args\n * @returns {object}\n */\nfunction normalizeArgs(args) {\n var options = args[1], callback = args[2];\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n if (!(options instanceof Options)) {\n options = new Options(options);\n }\n return {\n schema: args[0],\n options: options,\n callback: callback\n };\n}\n", diff --git a/dist/ref-parser.min.js b/dist/ref-parser.min.js index 8ba9f0de..d9aa62de 100644 --- a/dist/ref-parser.min.js +++ b/dist/ref-parser.min.js @@ -1,6 +1,6 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.$RefParser = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 1) {\n // The current value has additional properties (other than \"$ref\"),\n // so merge the resolved value rather than completely replacing the reference\n var merged = {};\n Object.keys(currentValue).forEach(function(key) {\n if (key !== '$ref') {\n merged[key] = currentValue[key];\n }\n });\n Object.keys(resolvedValue).forEach(function(key) {\n if (!(key in merged)) {\n merged[key] = resolvedValue[key];\n }\n });\n return merged;\n }\n else {\n // Completely replace the original reference with the resolved value\n return resolvedValue;\n }\n}\n\n/**\n * Called when a circular reference is found.\n * It sets the {@link $Refs#circular} flag, and throws an error if options.$refs.circular is false.\n *\n * @param {string} keyPath - The JSON Reference path of the circular reference\n * @param {$Refs} $refs\n * @param {$RefParserOptions} options\n * @returns {boolean} - always returns true, to indicate that a circular reference was found\n */\nfunction foundCircularReference(keyPath, $refs, options) {\n $refs.circular = true;\n if (!options.$refs.circular) {\n throw ono.reference('Circular $ref pointer found at %s', keyPath);\n }\n return true;\n}\n", "'use strict';\n\nvar http = require('http'),\n https = require('https'),\n url = require('url'),\n util = require('./util'),\n Promise = require('./promise'),\n ono = require('ono');\n\nmodule.exports = download;\n\n/**\n * Downloads the given file.\n *\n * @param {Url|string} u - The url to download (can be a parsed {@link Url} object)\n * @param {$RefParserOptions} options\n * @param {number} [redirects] - The redirect URLs that have already been followed\n *\n * @returns {Promise}\n * The promise resolves with the raw downloaded data, or rejects if there is an HTTP error.\n */\nfunction download(u, options, redirects) {\n return new Promise(function(resolve, reject) {\n u = url.parse(u);\n redirects = redirects || [];\n redirects.push(u.href);\n\n get(u, options)\n .then(function(res) {\n if (res.statusCode >= 400) {\n throw ono({status: res.statusCode}, 'HTTP ERROR %d', res.statusCode);\n }\n else if (res.statusCode >= 300) {\n if (redirects.length > options.http.redirects) {\n reject(ono({status: res.statusCode}, 'Error downloading %s. \\nToo many redirects: \\n %s',\n redirects[0], redirects.join(' \\n ')));\n }\n else if (!res.headers.location) {\n throw ono({status: res.statusCode}, 'HTTP %d redirect with no location header', res.statusCode);\n }\n else {\n util.debug('HTTP %d redirect %s -> %s', res.statusCode, u.href, res.headers.location);\n var redirectTo = url.resolve(u, res.headers.location);\n download(redirectTo, options, redirects).then(resolve, reject);\n }\n }\n else if (res.statusCode === 204 && !options.allow.empty) {\n throw ono({status: 204}, 'HTTP 204 (No Content)');\n }\n else {\n resolve(res.body || new Buffer(0));\n }\n })\n .catch(function(err) {\n reject(ono(err, 'Error downloading', u.href));\n });\n });\n}\n\n/**\n * Sends an HTTP GET request.\n *\n * @param {Url} u - A parsed {@link Url} object\n * @param {$RefParserOptions} options\n *\n * @returns {Promise}\n * The promise resolves with the HTTP Response object.\n */\nfunction get(u, options) {\n return new Promise(function(resolve, reject) {\n util.debug('GET', u.href);\n\n var protocol = u.protocol === 'https:' ? https : http;\n var req = protocol.get({\n hostname: u.hostname,\n port: u.port,\n path: u.path,\n auth: u.auth,\n headers: options.http.headers,\n withCredentials: options.http.withCredentials\n });\n\n if (typeof req.setTimeout === 'function') {\n req.setTimeout(options.http.timeout);\n }\n\n req.on('timeout', function() {\n req.abort();\n });\n\n req.on('error', reject);\n\n req.once('response', function(res) {\n res.body = new Buffer(0);\n\n res.on('data', function(data) {\n res.body = Buffer.concat([res.body, new Buffer(data)]);\n });\n\n res.on('error', reject);\n\n res.on('end', function() {\n resolve(res);\n });\n });\n });\n}\n", "'use strict';\n\nvar Promise = require('./promise'),\n Options = require('./options'),\n $Refs = require('./refs'),\n $Ref = require('./ref'),\n read = require('./read'),\n resolve = require('./resolve'),\n bundle = require('./bundle'),\n dereference = require('./dereference'),\n util = require('./util'),\n url = require('url'),\n maybe = require('call-me-maybe'),\n ono = require('ono');\n\nmodule.exports = $RefParser;\nmodule.exports.YAML = require('./yaml');\n\n/**\n * This class parses a JSON schema, builds a map of its JSON references and their resolved values,\n * and provides methods for traversing, manipulating, and dereferencing those references.\n *\n * @constructor\n */\nfunction $RefParser() {\n /**\n * The parsed (and possibly dereferenced) JSON schema object\n *\n * @type {object}\n * @readonly\n */\n this.schema = null;\n\n /**\n * The resolved JSON references\n *\n * @type {$Refs}\n */\n this.$refs = new $Refs();\n\n /**\n * The file path or URL of the main JSON schema file.\n * This will be empty if the schema was passed as an object rather than a path.\n *\n * @type {string}\n * @protected\n */\n this._basePath = '';\n}\n\n/**\n * Parses the given JSON schema.\n * This method does not resolve any JSON references.\n * It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed\n * @param {function} [callback] - An error-first callback. The second parameter is the parsed JSON schema object.\n * @returns {Promise} - The returned promise resolves with the parsed JSON schema object.\n */\n$RefParser.parse = function(schema, options, callback) {\n var Class = this; // eslint-disable-line consistent-this\n return new Class().parse(schema, options, callback);\n};\n\n/**\n * Parses the given JSON schema.\n * This method does not resolve any JSON references.\n * It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed\n * @param {function} [callback] - An error-first callback. The second parameter is the parsed JSON schema object.\n * @returns {Promise} - The returned promise resolves with the parsed JSON schema object.\n */\n$RefParser.prototype.parse = function(schema, options, callback) {\n var args = normalizeArgs(arguments);\n\n if (args.schema && typeof args.schema === 'object') {\n // The schema is an object, not a path/url\n this.schema = args.schema;\n this._basePath = '';\n var $ref = new $Ref(this.$refs, this._basePath);\n $ref.setValue(this.schema, args.options);\n\n return maybe(args.callback, Promise.resolve(this.schema));\n }\n\n if (!args.schema || typeof args.schema !== 'string') {\n var err = ono('Expected a file path, URL, or object. Got %s', args.schema);\n return maybe(args.callback, Promise.reject(err));\n }\n\n var me = this;\n\n // Resolve the absolute path of the schema\n args.schema = util.path.localPathToUrl(args.schema);\n args.schema = url.resolve(util.path.cwd(), args.schema);\n this._basePath = util.path.stripHash(args.schema);\n\n // Read the schema file/url\n return read(args.schema, this.$refs, args.options)\n .then(function(cached$Ref) {\n var value = cached$Ref.$ref.value;\n if (!value || typeof value !== 'object' || value instanceof Buffer) {\n throw ono.syntax('\"%s\" is not a valid JSON Schema', me._basePath);\n }\n else {\n me.schema = value;\n return maybe(args.callback, Promise.resolve(me.schema));\n }\n })\n .catch(function(e) {\n return maybe(args.callback, Promise.reject(e));\n });\n};\n\n/**\n * Parses the given JSON schema and resolves any JSON references, including references in\n * externally-referenced files.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed and resolved\n * @param {function} [callback]\n * - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references\n *\n * @returns {Promise}\n * The returned promise resolves with a {@link $Refs} object containing the resolved JSON references\n */\n$RefParser.resolve = function(schema, options, callback) {\n var Class = this; // eslint-disable-line consistent-this\n return new Class().resolve(schema, options, callback);\n};\n\n/**\n * Parses the given JSON schema and resolves any JSON references, including references in\n * externally-referenced files.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed and resolved\n * @param {function} [callback]\n * - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references\n *\n * @returns {Promise}\n * The returned promise resolves with a {@link $Refs} object containing the resolved JSON references\n */\n$RefParser.prototype.resolve = function(schema, options, callback) {\n var me = this;\n var args = normalizeArgs(arguments);\n\n return this.parse(args.schema, args.options)\n .then(function() {\n return resolve(me, args.options);\n })\n .then(function() {\n return maybe(args.callback, Promise.resolve(me.$refs));\n })\n .catch(function(err) {\n return maybe(args.callback, Promise.reject(err));\n });\n};\n\n/**\n * Parses the given JSON schema, resolves any JSON references, and bundles all external references\n * into the main JSON schema. This produces a JSON schema that only has *internal* references,\n * not any *external* references.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced\n * @param {function} [callback] - An error-first callback. The second parameter is the bundled JSON schema object\n * @returns {Promise} - The returned promise resolves with the bundled JSON schema object.\n */\n$RefParser.bundle = function(schema, options, callback) {\n var Class = this; // eslint-disable-line consistent-this\n return new Class().bundle(schema, options, callback);\n};\n\n/**\n * Parses the given JSON schema, resolves any JSON references, and bundles all external references\n * into the main JSON schema. This produces a JSON schema that only has *internal* references,\n * not any *external* references.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced\n * @param {function} [callback] - An error-first callback. The second parameter is the bundled JSON schema object\n * @returns {Promise} - The returned promise resolves with the bundled JSON schema object.\n */\n$RefParser.prototype.bundle = function(schema, options, callback) {\n var me = this;\n var args = normalizeArgs(arguments);\n\n return this.resolve(args.schema, args.options)\n .then(function() {\n bundle(me, args.options);\n return maybe(args.callback, Promise.resolve(me.schema));\n })\n .catch(function(err) {\n return maybe(args.callback, Promise.reject(err));\n });\n};\n\n/**\n * Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.\n * That is, all JSON references are replaced with their resolved values.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced\n * @param {function} [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object\n * @returns {Promise} - The returned promise resolves with the dereferenced JSON schema object.\n */\n$RefParser.dereference = function(schema, options, callback) {\n var Class = this; // eslint-disable-line consistent-this\n return new Class().dereference(schema, options, callback);\n};\n\n/**\n * Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.\n * That is, all JSON references are replaced with their resolved values.\n *\n * @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.\n * @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced\n * @param {function} [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object\n * @returns {Promise} - The returned promise resolves with the dereferenced JSON schema object.\n */\n$RefParser.prototype.dereference = function(schema, options, callback) {\n var me = this;\n var args = normalizeArgs(arguments);\n\n return this.resolve(args.schema, args.options)\n .then(function() {\n dereference(me, args.options);\n return maybe(args.callback, Promise.resolve(me.schema));\n })\n .catch(function(err) {\n return maybe(args.callback, Promise.reject(err));\n });\n};\n\n/**\n * Normalizes the given arguments, accounting for optional args.\n *\n * @param {Arguments} args\n * @returns {object}\n */\nfunction normalizeArgs(args) {\n var options = args[1], callback = args[2];\n if (typeof options === 'function') {\n callback = options;\n options = undefined;\n }\n if (!(options instanceof Options)) {\n options = new Options(options);\n }\n return {\n schema: args[0],\n options: options,\n callback: callback\n };\n}\n", diff --git a/lib/bundle.js b/lib/bundle.js index db309684..46bc5f4e 100644 --- a/lib/bundle.js +++ b/lib/bundle.js @@ -1,5 +1,5 @@ /** ! - * JSON Schema $Ref Parser v2.0.0 + * JSON Schema $Ref Parser v2.1.0 * * @link https://github.com/BigstickCarpet/json-schema-ref-parser * @license MIT diff --git a/package.json b/package.json index b534130a..01834e08 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "json-schema-ref-parser", - "version": "2.0.0", + "version": "2.1.0", "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers", "keywords": [ "json",