Skip to content

Commit 93c436a

Browse files
Created the stub of the bundle method
1 parent 3cd8095 commit 93c436a

8 files changed

Lines changed: 441 additions & 302 deletions

File tree

dist/ref-parser.js

Lines changed: 213 additions & 147 deletions
Large diffs are not rendered by default.

dist/ref-parser.js.map

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ref-parser.min.js

Lines changed: 148 additions & 143 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ref-parser.min.js.map

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/_preamble.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
*/

lib/bundle.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
module.exports = bundle;
4+
5+
/**
6+
* Bundles all external JSON references into the main JSON schema, thus resulting in a schema that
7+
* only has *internal* references, not any *external* references.
8+
* This method mutates the JSON schema object, adding new references and remapping existing ones.
9+
*
10+
* @param {$RefParser} parser
11+
* @param {ParserOptions} options
12+
*/
13+
function bundle(parser, options) {
14+
throw new Error('The "bundle" method is not implemented yet. It will be implemented before the final alpha.');
15+
}

lib/index.js

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
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

93
var 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

2419
module.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.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"karma": "karma start --single-run",
3030
"test": "npm run browserify -- --test && npm run istanbul && npm run karma",
3131
"upgrade": "ncu --upgradeAll && npm update && bower update",
32-
"bump": "bump --prerelease --grep lib/index.js dist/* --tag --push --all",
32+
"bump": "bump --prerelease --grep lib/_preamble.js dist/* --tag --push --all",
3333
"release": "npm run upgrade && npm test && npm run bump && npm publish"
3434
},
3535
"repository": {
@@ -67,4 +67,4 @@
6767
"lodash": "^3.10.1",
6868
"ono": "^1.0.22"
6969
}
70-
}
70+
}

0 commit comments

Comments
 (0)