Skip to content

Commit 56c8652

Browse files
feat(common): enhance URL parsing to use environment variables on openapi import (hoppscotch#5232)
Co-authored-by: jamesgeorge007 <[email protected]>
1 parent 39124fb commit 56c8652

File tree

1 file changed

+5
-1
lines changed
  • packages/hoppscotch-common/src/helpers/import-export/import

1 file changed

+5
-1
lines changed

packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ const parseOpenAPIUrl = (
754754
**/
755755

756756
if (objectHasProperty(doc, "swagger")) {
757+
// TODO: dynamically add doc.host, doc.basePath value as variables in the environment if available. or notify user to add it.
758+
// add base url variable to each request
757759
const host = doc.host?.trim() || "<<baseUrl>>"
758760
const basePath = doc.basePath?.trim() || ""
759761
return `${host}${basePath}`
@@ -765,7 +767,9 @@ const parseOpenAPIUrl = (
765767
* Relevant v3 reference: https://swagger.io/specification/#server-object
766768
**/
767769
if (objectHasProperty(doc, "servers")) {
768-
return doc.servers?.[0]?.url ?? "<<baseUrl>>"
770+
// TODO: dynamically add server URL value as variable in the environment if available, or notify user to add it.
771+
const serverUrl = doc.servers?.[0]?.url
772+
return !serverUrl || serverUrl === "./" ? "<<baseUrl>>" : serverUrl
769773
}
770774

771775
// If the document is neither v2 nor v3 or missing required fields

0 commit comments

Comments
 (0)