forked from extern/bruno
Merge pull request #965 from Art051/bugfix/openapi-import-selfref-infinite-loop
Fix inifinite loop in openapi-spec import with self-references
This commit is contained in:
commit
3bd7bc75a8
@ -187,18 +187,24 @@ const transformOpenapiRequestItem = (request) => {
|
||||
return brunoRequestItem;
|
||||
};
|
||||
|
||||
const resolveRefs = (spec, components = spec.components) => {
|
||||
const resolveRefs = (spec, components = spec.components, visitedItems = new Set()) => {
|
||||
if (!spec || typeof spec !== 'object') {
|
||||
return spec;
|
||||
}
|
||||
|
||||
if (Array.isArray(spec)) {
|
||||
return spec.map((item) => resolveRefs(item, components));
|
||||
return spec.map((item) => resolveRefs(item, components, visitedItems));
|
||||
}
|
||||
|
||||
if ('$ref' in spec) {
|
||||
const refPath = spec.$ref;
|
||||
|
||||
if (visitedItems.has(refPath)) {
|
||||
return spec;
|
||||
} else {
|
||||
visitedItems.add(refPath);
|
||||
}
|
||||
|
||||
if (refPath.startsWith('#/components/')) {
|
||||
// Local reference within components
|
||||
const refKeys = refPath.replace('#/components/', '').split('/');
|
||||
@ -213,7 +219,7 @@ const resolveRefs = (spec, components = spec.components) => {
|
||||
}
|
||||
}
|
||||
|
||||
return resolveRefs(ref, components);
|
||||
return resolveRefs(ref, components, visitedItems);
|
||||
} else {
|
||||
// Handle external references (not implemented here)
|
||||
// You would need to fetch the external reference and resolve it.
|
||||
@ -223,7 +229,7 @@ const resolveRefs = (spec, components = spec.components) => {
|
||||
|
||||
// Recursively resolve references in nested objects
|
||||
for (const prop in spec) {
|
||||
spec[prop] = resolveRefs(spec[prop], components);
|
||||
spec[prop] = resolveRefs(spec[prop], components, visitedItems);
|
||||
}
|
||||
|
||||
return spec;
|
||||
|
Loading…
Reference in New Issue
Block a user