From 7589c57e8679cdf5cf5b9d391b21e9d0fa20c8d8 Mon Sep 17 00:00:00 2001 From: nivedin Date: Wed, 14 Feb 2024 20:50:53 +0530 Subject: [PATCH] refactor: update postman import for request variable --- .../helpers/import-export/import/postman.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts b/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts index bb9603dc0..c9c9d8eb3 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts @@ -5,6 +5,7 @@ import { QueryParam, RequestAuthDefinition, VariableDefinition, + Variable, } from "postman-collection" import { HoppRESTAuth, @@ -18,6 +19,7 @@ import { ValidContentTypes, knownContentTypes, FormDataKeyValue, + HoppRESTRequestVariable, } from "@hoppscotch/data" import { pipe, flow } from "fp-ts/function" import * as S from "fp-ts/string" @@ -91,6 +93,25 @@ const getHoppReqParams = (item: Item): HoppRESTParam[] => { ) } +const getHoppReqVariables = (item: Item) => { + return pipe( + item.request.url.variables.all(), + A.filter( + (variable): variable is Variable => + variable.key !== undefined && + variable.key !== null && + variable.key.length > 0 + ), + A.map((variable) => { + return { + key: replacePMVarTemplating(variable.key ?? ""), + value: replacePMVarTemplating(variable.value ?? ""), + active: !variable.disabled, + } + }) + ) +} + type PMRequestAuthDef< AuthType extends RequestAuthDefinition["type"] = RequestAuthDefinition["type"], @@ -280,6 +301,7 @@ const getHoppRequest = (item: Item): HoppRESTRequest => { params: getHoppReqParams(item), auth: getHoppReqAuth(item), body: getHoppReqBody(item), + requestVariables: getHoppReqVariables(item), // TODO: Decide about this preRequestScript: "",