Skip to content

Commit

Permalink
fix: avoid endless recursion in schema-walker in some cases
Browse files Browse the repository at this point in the history
fixes #418, #395
  • Loading branch information
RomanHotsiy committed Feb 23, 2018
1 parent 07d1a7b commit 309cc23
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/services/schema-normalizer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 309cc23

Please sign in to comment.