From 56c86529902ef35813ec0756b9ff9b78afba281b Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Mon, 14 Jul 2025 14:42:28 +0600 Subject: [PATCH] feat(common): enhance URL parsing to use environment variables on openapi import (#5232) Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com> --- .../src/helpers/import-export/import/openapi.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 9d2a4576..71b34002 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts @@ -754,6 +754,8 @@ const parseOpenAPIUrl = ( **/ if (objectHasProperty(doc, "swagger")) { + // TODO: dynamically add doc.host, doc.basePath value as variables in the environment if available. or notify user to add it. + // add base url variable to each request const host = doc.host?.trim() || "<>" const basePath = doc.basePath?.trim() || "" return `${host}${basePath}` @@ -765,7 +767,9 @@ const parseOpenAPIUrl = ( * Relevant v3 reference: https://swagger.io/specification/#server-object **/ if (objectHasProperty(doc, "servers")) { - return doc.servers?.[0]?.url ?? "<>" + // TODO: dynamically add server URL value as variable in the environment if available, or notify user to add it. + const serverUrl = doc.servers?.[0]?.url + return !serverUrl || serverUrl === "./" ? "<>" : serverUrl } // If the document is neither v2 nor v3 or missing required fields