Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
feat(common): enhance URL parsing to use environment variables on openapi import (#5232)
Anwarul Islam56c86529902e
diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts b/packages/hoppscotch-common/src/helpers/import-export/import/openapi.tsindex 9d2a45762..71b340022 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 requestconst host = doc.host?.trim() || "<<baseUrl>>"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 ?? "<<baseUrl>>"+ // 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 === "./" ? "<<baseUrl>>" : serverUrl}// If the document is neither v2 nor v3 or missing required fields