Skip to content

Commit 663e4e9

Browse files
- refactored the $RefParser static methods to support inheritance
- renamed ParserOptions to $RefParserOptions
1 parent 92707d4 commit 663e4e9

15 files changed

Lines changed: 393 additions & 393 deletions

dist/ref-parser.js

Lines changed: 182 additions & 181 deletions
Large diffs are not rendered by default.

dist/ref-parser.js.map

Lines changed: 10 additions & 12 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: 143 additions & 145 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: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/_preamble.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/bundle.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**!
2+
* JSON Schema $Ref Parser v1.0.0-alpha.13
3+
*
4+
* @link https://github.com/BigstickCarpet/json-schema-ref-parser
5+
* @license MIT
6+
*/
17
'use strict';
28

39
module.exports = bundle;
@@ -8,7 +14,7 @@ module.exports = bundle;
814
* This method mutates the JSON schema object, adding new references and remapping existing ones.
915
*
1016
* @param {$RefParser} parser
11-
* @param {ParserOptions} options
17+
* @param {$RefParserOptions} options
1218
*/
1319
function bundle(parser, options) {
1420
throw new Error('The "bundle" method is not implemented yet. It will be implemented before the final alpha.');

lib/dereference.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = dereference;
1414
* This method mutates the JSON schema object, replacing JSON references with their resolved value.
1515
*
1616
* @param {$RefParser} parser
17-
* @param {ParserOptions} options
17+
* @param {$RefParserOptions} options
1818
*/
1919
function dereference(parser, options) {
2020
util.debug('Dereferencing $ref pointers in %s', parser._basePath);
@@ -28,7 +28,7 @@ function dereference(parser, options) {
2828
* @param {string} path - The path to use for resolving relative JSON references
2929
* @param {object[]} parents - An array of the parent objects that have already been dereferenced
3030
* @param {$Refs} $refs - The resolved JSON references
31-
* @param {ParserOptions} options
31+
* @param {$RefParserOptions} options
3232
*/
3333
function crawl(obj, path, parents, $refs, options) {
3434
if (_isObject(obj) || _isArray(obj)) {

lib/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ var Promise = require('./promise'),
1717
_isString = require('lodash/lang/isString');
1818

1919
module.exports = $RefParser;
20-
module.falsy && require('./_preamble');
2120

2221
/**
2322
* This class parses a JSON schema, builds a map of its JSON references and their resolved values,
@@ -54,12 +53,13 @@ function $RefParser() {
5453
* It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.
5554
*
5655
* @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.
57-
* @param {ParserOptions} [options] - Options that determine how the schema is parsed
56+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed
5857
* @param {function} [callback] - An error-first callback. The second parameter is the parsed JSON schema object.
5958
* @returns {Promise} - The returned promise resolves with the parsed JSON schema object.
6059
*/
6160
$RefParser.parse = function(schema, options, callback) {
62-
return new $RefParser().parse(schema, options, callback);
61+
var Class = this;
62+
return new Class().parse(schema, options, callback);
6363
};
6464

6565
/**
@@ -68,7 +68,7 @@ $RefParser.parse = function(schema, options, callback) {
6868
* It just reads a single file in JSON or YAML format, and parse it as a JavaScript object.
6969
*
7070
* @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.
71-
* @param {ParserOptions} [options] - Options that determine how the schema is parsed
71+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed
7272
* @param {function} [callback] - An error-first callback. The second parameter is the parsed JSON schema object.
7373
* @returns {Promise} - The returned promise resolves with the parsed JSON schema object.
7474
*/
@@ -124,23 +124,24 @@ $RefParser.prototype.parse = function(schema, options, callback) {
124124
* externally-referenced files.
125125
*
126126
* @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.
127-
* @param {ParserOptions} [options] - Options that determine how the schema is parsed and resolved
127+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed and resolved
128128
* @param {function} [callback]
129129
* - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references
130130
*
131131
* @returns {Promise}
132132
* The returned promise resolves with a {@link $Refs} object containing the resolved JSON references
133133
*/
134134
$RefParser.resolve = function(schema, options, callback) {
135-
return new $RefParser().resolve(schema, options, callback);
135+
var Class = this;
136+
return new Class().resolve(schema, options, callback);
136137
};
137138

138139
/**
139140
* Parses the given JSON schema and resolves any JSON references, including references in
140141
* externally-referenced files.
141142
*
142143
* @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.
143-
* @param {ParserOptions} [options] - Options that determine how the schema is parsed and resolved
144+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed and resolved
144145
* @param {function} [callback]
145146
* - An error-first callback. The second parameter is a {@link $Refs} object containing the resolved JSON references
146147
*
@@ -176,12 +177,13 @@ $RefParser.prototype.resolve = function(schema, options, callback) {
176177
* not any *external* references.
177178
*
178179
* @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 {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
180181
* @param {function} [callback] - An error-first callback. The second parameter is the bundled JSON schema object
181182
* @returns {Promise} - The returned promise resolves with the bundled JSON schema object.
182183
*/
183184
$RefParser.bundle = function(schema, options, callback) {
184-
return new $RefParser().bundle(schema, options, callback);
185+
var Class = this;
186+
return new Class().bundle(schema, options, callback);
185187
};
186188

187189
/**
@@ -190,7 +192,7 @@ $RefParser.bundle = function(schema, options, callback) {
190192
* not any *external* references.
191193
*
192194
* @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
195+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
194196
* @param {function} [callback] - An error-first callback. The second parameter is the bundled JSON schema object
195197
* @returns {Promise} - The returned promise resolves with the bundled JSON schema object.
196198
*/
@@ -220,20 +222,21 @@ $RefParser.prototype.bundle = function(schema, options, callback) {
220222
* That is, all JSON references are replaced with their resolved values.
221223
*
222224
* @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.
223-
* @param {ParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
225+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
224226
* @param {function} [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
225227
* @returns {Promise} - The returned promise resolves with the dereferenced JSON schema object.
226228
*/
227229
$RefParser.dereference = function(schema, options, callback) {
228-
return new $RefParser().dereference(schema, options, callback);
230+
var Class = this;
231+
return new Class().dereference(schema, options, callback);
229232
};
230233

231234
/**
232235
* Parses the given JSON schema, resolves any JSON references, and dereferences the JSON schema.
233236
* That is, all JSON references are replaced with their resolved values.
234237
*
235238
* @param {string|object} schema - The file path or URL of the JSON schema. Or a JSON schema object.
236-
* @param {ParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
239+
* @param {$RefParserOptions} [options] - Options that determine how the schema is parsed, resolved, and dereferenced
237240
* @param {function} [callback] - An error-first callback. The second parameter is the dereferenced JSON schema object
238241
* @returns {Promise} - The returned promise resolves with the dereferenced JSON schema object.
239242
*/

lib/options.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
var _merge = require('lodash/object/merge');
44

5-
module.exports = ParserOptions;
5+
module.exports = $RefParserOptions;
66

77
/**
88
* Options that determine how JSON schemas are parsed, dereferenced, and cached.
99
*
10-
* @param {object|ParserOptions} [options] - Overridden options
10+
* @param {object|$RefParserOptions} [options] - Overridden options
1111
* @constructor
1212
*/
13-
function ParserOptions(options) {
13+
function $RefParserOptions(options) {
1414
/**
1515
* Determines what types of files can be parsed
1616
*/

lib/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = parse;
1313
*
1414
* @param {string|Buffer} data - The data to be parsed
1515
* @param {string} path - The file path or URL that `data` came from
16-
* @param {ParserOptions} options
16+
* @param {$RefParserOptions} options
1717
*
1818
* @returns {string|Buffer|object}
1919
* If `data` can be parsed as YAML or JSON, then the returned value is a JavaScript object.

0 commit comments

Comments
 (0)