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,
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 <HoppRESTRequestVariable>{
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: "",