refactor: update openapi import

This commit is contained in:
nivedin
2024-02-15 14:15:48 +05:30
committed by Andrew Bastin
parent 7589c57e86
commit d44083a380

View File

@@ -16,6 +16,7 @@ import {
makeRESTRequest,
HoppCollection,
makeCollection,
HoppRESTRequestVariable,
} from "@hoppscotch/data"
import { pipe, flow } from "fp-ts/function"
import * as A from "fp-ts/Array"
@@ -82,6 +83,27 @@ const parseOpenAPIParams = (params: OpenAPIParamsType[]): HoppRESTParam[] =>
)
)
const parseOpenAPIVariables = (
variables: OpenAPIParamsType[]
): HoppRESTRequestVariable[] =>
pipe(
variables,
A.filterMap(
flow(
O.fromPredicate((param) => param.in === "path"),
O.map(
(param) =>
<HoppRESTRequestVariable>{
key: param.name,
value: "", // TODO: Can we do anything more ? (parse default values maybe)
active: true,
}
)
)
)
)
const parseOpenAPIHeaders = (params: OpenAPIParamsType[]): HoppRESTHeader[] =>
pipe(
params,
@@ -577,6 +599,10 @@ const convertPathToHoppReqs = (
preRequestScript: "",
testScript: "",
requestVariables: parseOpenAPIVariables(
(info.parameters as OpenAPIParamsType[] | undefined) ?? []
),
})
}),