From 0e4bbec96d5be2b63d79933a91a9c39ecd46a3d8 Mon Sep 17 00:00:00 2001 From: Anil Tallam Date: Fri, 29 Dec 2023 12:58:07 +0530 Subject: [PATCH] Handling request name conflicts while importing postman V2 collections Issue: In Postman, multiple requests in same folder can have same name. current import code is creating bruneRequestItems with same name which is causing only one of the original requests to be actaully created. Looks like bruno doesn't allow multiple requests with same name in a given folder. Fix: Append _ to conflicting request names within same folder. --- .../src/utils/importers/postman-collection.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/bruno-app/src/utils/importers/postman-collection.js b/packages/bruno-app/src/utils/importers/postman-collection.js index feacaf85aa..fcbfda5bfa 100644 --- a/packages/bruno-app/src/utils/importers/postman-collection.js +++ b/packages/bruno-app/src/utils/importers/postman-collection.js @@ -56,7 +56,8 @@ const convertV21Auth = (array) => { const importPostmanV2CollectionItem = (brunoParent, item, parentAuth) => { brunoParent.items = brunoParent.items || []; const folderMap = {}; - + const requestMap = {}; + each(item, (i) => { if (isItemAFolder(i)) { const baseFolderName = i.name; @@ -81,6 +82,15 @@ const importPostmanV2CollectionItem = (brunoParent, item, parentAuth) => { } } else { if (i.request) { + const baseRequestName = i.name; + let requestName = baseRequestName; + let count = 1; + + while (requestMap[requestName]) { + requestName = `${baseRequestName}_${count}`; + count++; + } + let url = ''; if (typeof i.request.url === 'string') { url = i.request.url; @@ -90,7 +100,7 @@ const importPostmanV2CollectionItem = (brunoParent, item, parentAuth) => { const brunoRequestItem = { uid: uuid(), - name: i.name, + name: requestName, type: 'http-request', request: { url: url, @@ -242,6 +252,7 @@ const importPostmanV2CollectionItem = (brunoParent, item, parentAuth) => { }); brunoParent.items.push(brunoRequestItem); + requestMap[requestName] = brunoRequestItem; } } });