From be29806f56b7c183c4b09d578b6a880d26c1e2ba Mon Sep 17 00:00:00 2001 From: Markus Ziller Date: Fri, 19 Feb 2016 09:55:57 +0100 Subject: [PATCH 1/3] Removes duplicated recursive call this.resolveAllOf has been called recursively twice which really caused the callstack to explode, from 6,000 to > 100,000,000 --- lib/resolver.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/resolver.js b/lib/resolver.js index 491512ca9..64f1c6035 100644 --- a/lib/resolver.js +++ b/lib/resolver.js @@ -670,9 +670,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)) { From cdf44e3428599c2e10888ced5699c68ad984ec4e Mon Sep 17 00:00:00 2001 From: Markus Ziller Date: Fri, 19 Feb 2016 09:56:31 +0100 Subject: [PATCH 2/3] Allows for complete disabling of allOf-Resolvment Speeds up parsing significantly --- lib/resolver.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/resolver.js b/lib/resolver.js index 64f1c6035..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 { From 16221e89728836b67668dab79a231ff6a1f9e033 Mon Sep 17 00:00:00 2001 From: Markus Ziller Date: Fri, 19 Feb 2016 10:15:57 +0100 Subject: [PATCH 3/3] calls new Resolver(..) with options object as argument --- lib/client.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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);