refactor: update postman import for request variable

This commit is contained in:
nivedin
2024-02-14 20:50:53 +05:30
committed by Andrew Bastin
parent c8009aec77
commit 7589c57e86

View File

@@ -5,6 +5,7 @@ import {
QueryParam, QueryParam,
RequestAuthDefinition, RequestAuthDefinition,
VariableDefinition, VariableDefinition,
Variable,
} from "postman-collection" } from "postman-collection"
import { import {
HoppRESTAuth, HoppRESTAuth,
@@ -18,6 +19,7 @@ import {
ValidContentTypes, ValidContentTypes,
knownContentTypes, knownContentTypes,
FormDataKeyValue, FormDataKeyValue,
HoppRESTRequestVariable,
} from "@hoppscotch/data" } from "@hoppscotch/data"
import { pipe, flow } from "fp-ts/function" import { pipe, flow } from "fp-ts/function"
import * as S from "fp-ts/string" 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 <HoppRESTRequestVariable>{
key: replacePMVarTemplating(variable.key ?? ""),
value: replacePMVarTemplating(variable.value ?? ""),
active: !variable.disabled,
}
})
)
}
type PMRequestAuthDef< type PMRequestAuthDef<
AuthType extends AuthType extends
RequestAuthDefinition["type"] = RequestAuthDefinition["type"], RequestAuthDefinition["type"] = RequestAuthDefinition["type"],
@@ -280,6 +301,7 @@ const getHoppRequest = (item: Item): HoppRESTRequest => {
params: getHoppReqParams(item), params: getHoppReqParams(item),
auth: getHoppReqAuth(item), auth: getHoppReqAuth(item),
body: getHoppReqBody(item), body: getHoppReqBody(item),
requestVariables: getHoppReqVariables(item),
// TODO: Decide about this // TODO: Decide about this
preRequestScript: "", preRequestScript: "",