1- /**!
2- * JSON Schema $Ref Parser v1.0.0-alpha.12
3- *
4- * @link https://github.com/BigstickCarpet/json-schema-ref-parser
5- * @license MIT
6- */
71'use strict' ;
82
93var Promise = require ( './promise' ) ,
104 Options = require ( './options' ) ,
115 $Refs = require ( './refs' ) ,
126 read = require ( './read' ) ,
137 resolve = require ( './resolve' ) ,
8+ bundle = require ( './bundle' ) ,
149 dereference = require ( './dereference' ) ,
1510 util = require ( './util' ) ,
1611 url = require ( 'url' ) ,
@@ -22,6 +17,7 @@ var Promise = require('./promise'),
2217 _isString = require ( 'lodash/lang/isString' ) ;
2318
2419module . exports = $RefParser ;
20+ module . falsy && require ( './_preamble' ) ;
2521
2622/**
2723 * This class parses a JSON schema, builds a map of its JSON references and their resolved values,
@@ -174,6 +170,51 @@ $RefParser.prototype.resolve = function(schema, options, callback) {
174170 } ) ;
175171} ;
176172
173+ /**
174+ * Parses the given JSON schema, resolves any JSON references, and bundles all external references
175+ * into the main JSON schema. This produces a JSON schema that only has *internal* references,
176+ * not any *external* references.
177+ *
178+ * @param {string|object } schema - The file path or URL of the JSON schema. Or a JSON schema object.
179+ * @param {ParserOptions } [options] - Options that determine how the schema is parsed, resolved, and dereferenced
180+ * @param {function } [callback] - An error-first callback. The second parameter is the bundled JSON schema object
181+ * @returns {Promise } - The returned promise resolves with the bundled JSON schema object.
182+ */
183+ $RefParser . bundle = function ( schema , options , callback ) {
184+ return new $RefParser ( ) . bundle ( schema , options , callback ) ;
185+ } ;
186+
187+ /**
188+ * Parses the given JSON schema, resolves any JSON references, and bundles all external references
189+ * into the main JSON schema. This produces a JSON schema that only has *internal* references,
190+ * not any *external* references.
191+ *
192+ * @param {string|object } schema - The file path or URL of the JSON schema. Or a JSON schema object.
193+ * @param {ParserOptions } [options] - Options that determine how the schema is parsed, resolved, and dereferenced
194+ * @param {function } [callback] - An error-first callback. The second parameter is the bundled JSON schema object
195+ * @returns {Promise } - The returned promise resolves with the bundled JSON schema object.
196+ */
197+ $RefParser . prototype . bundle = function ( schema , options , callback ) {
198+ if ( _isFunction ( options ) ) {
199+ callback = options ;
200+ options = undefined ;
201+ }
202+
203+ options = new Options ( options ) ;
204+ var me = this ;
205+
206+ return this . resolve ( schema , options )
207+ . then ( function ( ) {
208+ bundle ( me , options ) ;
209+ util . doCallback ( callback , null , me . schema ) ;
210+ return me . schema ;
211+ } )
212+ . catch ( function ( err ) {
213+ util . doCallback ( callback , err , me . schema ) ;
214+ return Promise . reject ( err ) ;
215+ } ) ;
216+ } ;
217+
177218/**
178219 * Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
179220 * That is, all JSON references are replaced with their resolved values.
0 commit comments