From a6ac98b7097f08ebf7287adfd9df8578cabb340d Mon Sep 17 00:00:00 2001 From: Sanjai Kumar <84461672+sanjai0py@users.noreply.github.com> Date: Sun, 15 Dec 2024 14:53:53 +0530 Subject: [PATCH] feat: add support for importing collection-level variables from PM collections (#3481) * feat: add support for importing collection-level variables from Postman collections * fix: add optional chaining for collection variables in Postman importer * Update postman-collection.js --------- Co-authored-by: Anoop M D --- .../src/utils/importers/postman-collection.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/bruno-app/src/utils/importers/postman-collection.js b/packages/bruno-app/src/utils/importers/postman-collection.js index 5ab2dc6c0..8dadf33b9 100644 --- a/packages/bruno-app/src/utils/importers/postman-collection.js +++ b/packages/bruno-app/src/utils/importers/postman-collection.js @@ -166,6 +166,17 @@ const importScriptsFromEvents = (events, requestObject, options, pushTranslation }); }; +const importCollectionLevelVariables = (variables, requestObject) => { + const vars = variables.map((v) => ({ + uid: uuid(), + name: v.key, + value: v.value, + enabled: true + })); + + requestObject.vars.req = vars; +}; + const importPostmanV2CollectionItem = (brunoParent, item, parentAuth, options) => { brunoParent.items = brunoParent.items || []; const folderMap = {}; @@ -494,6 +505,10 @@ const importPostmanV2Collection = (collection, options) => { importScriptsFromEvents(collection.event, brunoCollection.root.request, options, pushTranslationLog); } + if (collection?.variable){ + importCollectionLevelVariables(collection.variable, brunoCollection.root.request); + } + importPostmanV2CollectionItem(brunoCollection, collection.item, collection.auth, options); return brunoCollection;