diff --git a/lib/client.js b/lib/client.js index 7c678a617..ae40719d4 100644 --- a/lib/client.js +++ b/lib/client.js @@ -199,7 +199,7 @@ SwaggerClient.prototype.build = function (mock) { if (responseObj.swagger && parseInt(responseObj.swagger) === 2) { self.swaggerVersion = responseObj.swagger; - new Resolver().resolve(responseObj, self.url, self.buildFromSpec, self); + new Resolver(options).resolve(responseObj, self.url, self.buildFromSpec, self); self.isValid = true; } else { @@ -209,7 +209,7 @@ SwaggerClient.prototype.build = function (mock) { converter.setDocumentationLocation(self.url); converter.convert(responseObj, self.clientAuthorizations, self.options, function(spec) { self.swaggerObject = spec; - new Resolver().resolve(spec, self.url, self.buildFromSpec, self); + new Resolver(options).resolve(spec, self.url, self.buildFromSpec, self); self.isValid = true; }); } @@ -220,7 +220,7 @@ SwaggerClient.prototype.build = function (mock) { if (this.spec) { self.swaggerObject = this.spec; setTimeout(function () { - new Resolver().resolve(self.spec, self.buildFromSpec, self); + new Resolver(options).resolve(self.spec, self.buildFromSpec, self); }, 10); } else { this.clientAuthorizations.apply(obj); diff --git a/lib/resolver.js b/lib/resolver.js index 491512ca9..a26084e9b 100644 --- a/lib/resolver.js +++ b/lib/resolver.js @@ -11,7 +11,14 @@ var _ = { /** * Resolves a spec's remote references */ -var Resolver = module.exports = function () {}; +var Resolver = module.exports = function (options) { + //Ensures downwards compatibility if no explicit options object is provided + var DEFAULT_OPTIONS = { + disableAllOfResolving: false + }; + + this.options = options || DEFAULT_OPTIONS +}; Resolver.prototype.processAllOf = function(root, name, definition, resolutionTable, unresolvedRefs, spec) { var i, location, property; @@ -405,7 +412,9 @@ Resolver.prototype.finish = function (spec, root, resolutionTable, resolvedRefs, var existingUnresolved = this.countUnresolvedRefs(spec); if(existingUnresolved === 0 || this.iteration > 5) { - this.resolveAllOf(spec.definitions); + if(!this.options.disableAllOfResolving) { + this.resolveAllOf(spec.definitions); + } callback.call(this.scope, spec, unresolvedRefs); } else { @@ -670,9 +679,6 @@ Resolver.prototype.resolveAllOf = function(spec, obj, depth) { if(item === null) { throw new TypeError('Swagger 2.0 does not support null types (' + obj + '). See https://github.com/swagger-api/swagger-spec/issues/229.'); } - if(typeof item === 'object') { - this.resolveAllOf(spec, item, depth + 1); - } if(item && typeof item.allOf !== 'undefined') { var allOf = item.allOf; if(_.isArray(allOf)) {