From 99f5070f71f81ea074f0e3fe70e5bd2b273bed9b Mon Sep 17 00:00:00 2001 From: Akash K <57758277+amk-dev@users.noreply.github.com> Date: Tue, 23 Jan 2024 21:49:34 +0530 Subject: [PATCH] fix: unwanted double slashes when importing from openapi (#3745) --- .../helpers/import-export/import/openapi.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts b/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts index febf950eb..29600acf7 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts @@ -549,13 +549,19 @@ const convertPathToHoppReqs = ( ), // Construct request object - RA.map(({ method, info }) => - makeRESTRequest({ + RA.map(({ method, info }) => { + const openAPIUrl = parseOpenAPIUrl(doc) + const openAPIPath = replaceOpenApiPathTemplating(pathName) + + const endpoint = + openAPIUrl.endsWith("/") && openAPIPath.startsWith("/") + ? openAPIUrl + openAPIPath.slice(1) + : openAPIUrl + openAPIPath + + return makeRESTRequest({ name: info.operationId ?? info.summary ?? "Untitled Request", method: method.toUpperCase(), - endpoint: `${parseOpenAPIUrl(doc)}${replaceOpenApiPathTemplating( - pathName - )}`, + endpoint, // We don't need to worry about reference types as the Dereferencing pass should remove them params: parseOpenAPIParams( @@ -572,7 +578,7 @@ const convertPathToHoppReqs = ( preRequestScript: "", testScript: "", }) - ), + }), // Disable Readonly RA.toArray