From 309cc23de617e56f93e8124b2d4316df258db6b9 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 23 Feb 2018 14:21:30 +0200 Subject: [PATCH] fix: avoid endless recursion in schema-walker in some cases fixes #418, #395 --- lib/services/schema-normalizer.service.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/services/schema-normalizer.service.ts b/lib/services/schema-normalizer.service.ts index f60de63004..8d6a409d44 100644 --- a/lib/services/schema-normalizer.service.ts +++ b/lib/services/schema-normalizer.service.ts @@ -53,6 +53,15 @@ class SchemaWalker { if (obj == undefined || typeof(obj) !== 'object') { return; } + + if (obj['x-redoc-visited']) { + const res = visitor(obj, pointer); + obj['x-redoc-visited'] = false; + // circular, return only title and description + return { title: res.title, description: res.description } + } + + obj['x-redoc-visited'] = true; if (obj.properties) { let ptr = JsonPointer.join(pointer, ['properties']); SchemaWalker.walkEach(obj.properties, ptr, visitor); @@ -83,7 +92,9 @@ class SchemaWalker { } } - return visitor(obj, pointer); + const res = visitor(obj, pointer); + obj['x-redoc-visited'] = false; + return res; } private static walkEach(obj:Object, pointer:string, visitor:Function) {