refactor: update postman import for request variable
This commit is contained in:
@@ -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: "",
|
||||||
|
|||||||
Reference in New Issue
Block a user