fix: avoid endless recursion in schema-walker in some cases

fixes #418, #395
This commit is contained in:
Roman Hotsiy 2018-02-23 14:21:30 +02:00
parent 07d1a7bfc7
commit 309cc23de6
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -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) {