lib/deref.js
function deref(theSchema, optionalOptions, callbackFn) {
	var root, loaders, error, options, callback;

	options = optionalOptions || {};

	if (typeof options === 'function') {
		callback = options;
	} else {
		callback = callbackFn;
	}

	root = _.cloneDeep(theSchema);
	loaders = _loaders(require('./loader/local'), options);
	process.nextTick(function () {
		traverse(root, _visit, _done);
	});

	function _visit(node, key, owner, next) {
		if (node === root) {
			next();
		}
		if (typeof node.$ref === 'string') {
			_load(node.$ref, function (err, schema) {
				if (err) {
					error = err;
					return false;
				}
				owner[key] = schema;
				next();
			});
		} else {
			next();
		}

		function _load($ref, resolve) {
			if (!_evaluate(loaders, _try)) {
				resolve({
					message: 'no appropriate loader',
					$ref: $ref
				});
			}

			function _try(loader) {
				return loader(root, $ref, resolve);
			}
		}
	}

	function _done() {
		process.nextTick(function () {
			if (error) {
				callback(error);
			} else {
				callback(null, root);
			}
		});
	}
}
function deref(theSchema, optionalOptions, callbackFn) {
	var root, loaders, error, options, callback;

	options = optionalOptions || {};

	if (typeof options === 'function') {
		callback = options;
	} else {
		callback = callbackFn;
	}

	root = _.cloneDeep(theSchema);
	loaders = _loaders(require('./loader/local'), options);
	process.nextTick(function () {
		traverse(root, _visit, _done);
	});

	function _visit(node, key, owner, next) {
		if (node === root) {
			next();
		}
		if (typeof node.$ref === 'string') {
			_load(node.$ref, function (err, schema) {
				if (err) {
					error = err;
					return false;
				}
				owner[key] = schema;
				next();
			});
		} else {
			next();
		}

		function _load($ref, resolve) {
			if (!_evaluate(loaders, _try)) {
				resolve({
					message: 'no appropriate loader',
					$ref: $ref
				});
			}

			function _try(loader) {
				return loader(root, $ref, resolve);
			}
		}
	}

	function _done() {
		process.nextTick(function () {
			if (error) {
				callback(error);
			} else {
				callback(null, root);
			}
		});
	}
}
function deref ( theSchema , optionalOptions , callbackFn ) { var root , loaders , error , options , callback ; options = optionalOptions || { } ; if ( typeof options === 'function' ) { callback = options ; } else { callback = callbackFn ; } root = _ . cloneDeep ( theSchema ) ; loaders = _loaders ( require ( './loader/local' ) , options ) ; process . nextTick ( function ( ) { traverse ( root , _visit , _done ) ; } ) ; function _visit ( node , key , owner , next ) { if ( node === root ) { next ( ) ; } if ( typeof node . $ref === 'string' ) { _load ( node . $ref , function ( err , schema ) { if ( err ) { error = err ; return false ; } owner [ key ] = schema ; next ( ) ; } ) ; } else { next ( ) ; } function _load ( $ref , resolve ) { if ( ! _evaluate ( loaders , _try ) ) { resolve ( { message : 'no appropriate loader' , $ref : $ref } ) ; } function _try ( loader ) { return loader ( root , $ref , resolve ) ; } } } function _done ( ) { process . nextTick ( function ( ) { if ( error ) { callback ( error ) ; } else { callback ( null , root ) ; } } ) ; } }
Dereference a schema that using JSON references.

Default implementation supports only local references,
i.e. references that starts with “#“.
Custom loaders can be provided via the options object.

@context don't care.
@param theSchema: string
@param optionalOptions.loader | optionalOptions.loaders: function | [function]
A loader function or an array of loader functions.

Loader must be a function that returns truthy if it can handle the given reference, falsy otherwise.
Loader takes root schema, $ref and callback(err, schema) as parameters in that order.
A local loader that is always tested first, and other loaders provided in options are then tested by the order they being listed.

@param callbackFn: function
@return no return value.
Dereference a schema that using JSON references .