mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-16 17:51:48 +01:00
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;
|
return brunoRequestItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
const resolveRefs = (spec, components = spec.components) => {
|
const resolveRefs = (spec, components = spec.components, visitedItems = new Set()) => {
|
||||||
if (!spec || typeof spec !== 'object') {
|
if (!spec || typeof spec !== 'object') {
|
||||||
return spec;
|
return spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(spec)) {
|
if (Array.isArray(spec)) {
|
||||||
return spec.map((item) => resolveRefs(item, components));
|
return spec.map((item) => resolveRefs(item, components, visitedItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('$ref' in spec) {
|
if ('$ref' in spec) {
|
||||||
const refPath = spec.$ref;
|
const refPath = spec.$ref;
|
||||||
|
|
||||||
|
if (visitedItems.has(refPath)) {
|
||||||
|
return spec;
|
||||||
|
} else {
|
||||||
|
visitedItems.add(refPath);
|
||||||
|
}
|
||||||
|
|
||||||
if (refPath.startsWith('#/components/')) {
|
if (refPath.startsWith('#/components/')) {
|
||||||
// Local reference within components
|
// Local reference within components
|
||||||
const refKeys = refPath.replace('#/components/', '').split('/');
|
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 {
|
} else {
|
||||||
// Handle external references (not implemented here)
|
// Handle external references (not implemented here)
|
||||||
// You would need to fetch the external reference and resolve it.
|
// 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
|
// Recursively resolve references in nested objects
|
||||||
for (const prop in spec) {
|
for (const prop in spec) {
|
||||||
spec[prop] = resolveRefs(spec[prop], components);
|
spec[prop] = resolveRefs(spec[prop], components, visitedItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
return spec;
|
return spec;
|
||||||
|
Loading…
Reference in New Issue
Block a user