fix: add body env resolution for har generation
This commit is contained in:
@@ -87,7 +87,10 @@ import { computed, ref, watch } from "@nuxtjs/composition-api"
|
|||||||
import * as O from "fp-ts/Option"
|
import * as O from "fp-ts/Option"
|
||||||
import { useCodemirror } from "~/helpers/editor/codemirror"
|
import { useCodemirror } from "~/helpers/editor/codemirror"
|
||||||
import { copyToClipboard } from "~/helpers/utils/clipboard"
|
import { copyToClipboard } from "~/helpers/utils/clipboard"
|
||||||
import { getEffectiveRESTRequest } from "~/helpers/utils/EffectiveURL"
|
import {
|
||||||
|
getEffectiveRESTRequest,
|
||||||
|
resolvesEnvsInBody,
|
||||||
|
} from "~/helpers/utils/EffectiveURL"
|
||||||
import { getCurrentEnvironment } from "~/newstore/environments"
|
import { getCurrentEnvironment } from "~/newstore/environments"
|
||||||
import { getRESTRequest } from "~/newstore/RESTSession"
|
import { getRESTRequest } from "~/newstore/RESTSession"
|
||||||
import { useI18n, useToast } from "~/helpers/utils/composables"
|
import { useI18n, useToast } from "~/helpers/utils/composables"
|
||||||
@@ -118,10 +121,8 @@ const copyIcon = ref("copy")
|
|||||||
const errorState = ref(false)
|
const errorState = ref(false)
|
||||||
|
|
||||||
const requestCode = computed(() => {
|
const requestCode = computed(() => {
|
||||||
const effectiveRequest = getEffectiveRESTRequest(
|
const env = getCurrentEnvironment()
|
||||||
request.value,
|
const effectiveRequest = getEffectiveRESTRequest(request.value, env)
|
||||||
getCurrentEnvironment()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!props.show) return ""
|
if (!props.show) return ""
|
||||||
|
|
||||||
@@ -129,6 +130,7 @@ const requestCode = computed(() => {
|
|||||||
codegenType.value,
|
codegenType.value,
|
||||||
makeRESTRequest({
|
makeRESTRequest({
|
||||||
...effectiveRequest,
|
...effectiveRequest,
|
||||||
|
body: resolvesEnvsInBody(effectiveRequest.body, env),
|
||||||
headers: effectiveRequest.effectiveFinalHeaders.map((header) => ({
|
headers: effectiveRequest.effectiveFinalHeaders.map((header) => ({
|
||||||
...header,
|
...header,
|
||||||
active: true,
|
active: true,
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { combineLatest, Observable } from "rxjs"
|
import { combineLatest, Observable } from "rxjs"
|
||||||
import { map } from "rxjs/operators"
|
import { map } from "rxjs/operators"
|
||||||
import { FormDataKeyValue, HoppRESTRequest } from "@hoppscotch/data"
|
import {
|
||||||
|
FormDataKeyValue,
|
||||||
|
HoppRESTReqBody,
|
||||||
|
HoppRESTRequest,
|
||||||
|
} from "@hoppscotch/data"
|
||||||
import { parseTemplateString, parseBodyEnvVariables } from "../templating"
|
import { parseTemplateString, parseBodyEnvVariables } from "../templating"
|
||||||
import { Environment, getGlobalVariables } from "~/newstore/environments"
|
import { Environment, getGlobalVariables } from "~/newstore/environments"
|
||||||
|
|
||||||
@@ -16,6 +20,36 @@ export interface EffectiveHoppRESTRequest extends HoppRESTRequest {
|
|||||||
effectiveFinalBody: FormData | string | null
|
effectiveFinalBody: FormData | string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolves environment variables in the body
|
||||||
|
export const resolvesEnvsInBody = (
|
||||||
|
body: HoppRESTReqBody,
|
||||||
|
env: Environment
|
||||||
|
): HoppRESTReqBody => {
|
||||||
|
if (!body.contentType) return body
|
||||||
|
|
||||||
|
if (body.contentType === "multipart/form-data") {
|
||||||
|
return {
|
||||||
|
contentType: "multipart/form-data",
|
||||||
|
body: body.body.map(
|
||||||
|
(entry) =>
|
||||||
|
<FormDataKeyValue>{
|
||||||
|
active: entry.active,
|
||||||
|
isFile: entry.isFile,
|
||||||
|
key: parseTemplateString(entry.key, env.variables),
|
||||||
|
value: entry.isFile
|
||||||
|
? entry.value
|
||||||
|
: parseTemplateString(entry.value, env.variables),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
contentType: body.contentType,
|
||||||
|
body: parseTemplateString(body.body, env.variables),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getFinalBodyFromRequest(
|
function getFinalBodyFromRequest(
|
||||||
request: HoppRESTRequest,
|
request: HoppRESTRequest,
|
||||||
env: Environment
|
env: Environment
|
||||||
|
|||||||
Reference in New Issue
Block a user