From 8a233fb4891ca6841577a05bc65c1b633ddefe74 Mon Sep 17 00:00:00 2001 From: lohit Date: Tue, 3 Sep 2024 17:32:29 +0530 Subject: [PATCH] fix: openapi collection import to not add protocol by default (#3011) * Update package.json * Update package.json * Update package.json * Update package.json * revert jest command * fix: openapi importwith server url * fix: updates --- .../bruno-app/src/utils/importers/openapi-collection.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/bruno-app/src/utils/importers/openapi-collection.js b/packages/bruno-app/src/utils/importers/openapi-collection.js index 5966563a7..1b6a2dd92 100644 --- a/packages/bruno-app/src/utils/importers/openapi-collection.js +++ b/packages/bruno-app/src/utils/importers/openapi-collection.js @@ -31,9 +31,8 @@ const readFile = (files) => { }; const ensureUrl = (url) => { - let protUrl = url.startsWith('http') ? url : `http://${url}`; - // replace any double or triple slashes - return protUrl.replace(/([^:]\/)\/+/g, '$1'); + // emoving multiple slashes after the protocol if it exists, or after the beginning of the string otherwise + return url.replace(/(^\w+:|^)\/{2,}/, '$1/'); }; const buildEmptyJsonBody = (bodySchema) => { @@ -67,7 +66,7 @@ const transformOpenapiRequestItem = (request) => { name: operationName, type: 'http-request', request: { - url: ensureUrl(request.global.server + '/' + path), + url: ensureUrl(request.global.server + path), method: request.method.toUpperCase(), auth: { mode: 'none', @@ -306,7 +305,7 @@ const getDefaultUrl = (serverObject) => { url = url.replace(`{${variableName}}`, sub); }); } - return url; + return url.endsWith('/') ? url : `${url}/`; }; const getSecurity = (apiSpec) => {