json-ref-resolver
json-ref-resolver copied to clipboard
Maximum callstack issue
Describe the bug
I have a case where a schema may return a circular dependency (even to itself) and this seems to cause a maximum callstack and/or out of memory exception. But only if a multi-level baseUri is specified.
To Reproduce
This causes an infinite loop:
const resolver = new Resolver({
resolvers: {
file: {
resolve(p) {
return { $ref: p.toString() };
}
}
}
});
await resolver.resolve([{ $ref: './a' }], {
baseUri: '/root1/root2' // Change this to /root1 and it's fine
});
Expected behavior
baseUri should support any number of nested folders.
Additional context
Just a guess, but I assume this is something related to the normalised key that's being stored as a visited node - but am unfamiliar with the code and haven't been able to dig into it yet.
Environment (remove any that are not applicable):
- Library version: v3.1.3
Just a followup, I get a similar issue if I use the transformRef property, even if the baseUri is only 1 level deep:
const resolver = new Resolver({
transformRef: uri => {
return uri.uri;
},
resolvers: {
file: {
resolve(p) {
return { $ref: p.toString() };
}
}
}
});
await resolver.resolve([{ $ref: './a' }], {
baseUri: '/root1'
});