mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-27 14:44:07 +00:00
Merge pull request #6117 from chirag-bruno/bugfix/postman-export-omit-collection-vars
fix: Exporting Bruno collection as Postman collection omits collection variables
This commit is contained in:
committed by
GitHub
parent
bc82536a82
commit
ee4c923bc5
@@ -118,7 +118,7 @@ export const brunoToPostman = (collection) => {
|
||||
|
||||
const generateCollectionVars = (collection) => {
|
||||
const pattern = /{{[^{}]+}}/g;
|
||||
let listOfVars = [];
|
||||
let collectionVars = [];
|
||||
|
||||
const findOccurrences = (obj, results) => {
|
||||
if (typeof obj === 'object') {
|
||||
@@ -131,20 +131,41 @@ export const brunoToPostman = (collection) => {
|
||||
}
|
||||
} else if (typeof obj === 'string') {
|
||||
obj.replace(pattern, (match) => {
|
||||
results.push(match.replace(/{{|}}/g, ''));
|
||||
const varKey = match[0].replace(/{{|}}/g, '');
|
||||
results.push({
|
||||
key: varKey,
|
||||
value: '',
|
||||
type: 'default'
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
findOccurrences(collection, listOfVars);
|
||||
findOccurrences(collection, collectionVars);
|
||||
|
||||
const finalArrayOfVars = [...new Set(listOfVars)];
|
||||
|
||||
return finalArrayOfVars.map((variable) => ({
|
||||
key: variable,
|
||||
value: '',
|
||||
// Add request and response vars
|
||||
let reqVars = (collection.root?.request?.vars?.req || []).map((v) => ({
|
||||
key: v.name,
|
||||
value: v.value,
|
||||
type: 'default'
|
||||
}));
|
||||
|
||||
let resVars = (collection.root?.request?.vars?.res || []).map((v) => ({
|
||||
key: v.name,
|
||||
value: v.value,
|
||||
type: 'default'
|
||||
}));
|
||||
|
||||
// Merge and deduplicate final result
|
||||
const allVars = [...reqVars, ...resVars, ...collectionVars];
|
||||
const finalVarsMap = new Map();
|
||||
allVars.forEach((v) => {
|
||||
if (!finalVarsMap.has(v.key)) {
|
||||
finalVarsMap.set(v.key, v);
|
||||
}
|
||||
});
|
||||
|
||||
return Array.from(finalVarsMap.values());
|
||||
};
|
||||
const generateEventSection = (item) => {
|
||||
const eventArray = [];
|
||||
|
||||
Reference in New Issue
Block a user