fix: issues with har generation

This commit is contained in:
Andrew Bastin
2022-01-03 10:48:18 +05:30
parent 78ad61f153
commit c3aedac77e
2 changed files with 22 additions and 12 deletions

View File

@@ -96,6 +96,7 @@ import {
CodegenName,
generateCode,
} from "~/helpers/new-codegen"
import { makeRESTRequest } from "~/../hoppscotch-data/dist"
const t = useI18n()
@@ -118,13 +119,27 @@ const errorState = ref(false)
const requestCode = computed(() => {
const effectiveRequest = getEffectiveRESTRequest(
request.value as any,
request.value,
getCurrentEnvironment()
)
if (!props.show) return ""
const result = generateCode(codegenType.value, effectiveRequest)
const result = generateCode(
codegenType.value,
makeRESTRequest({
...effectiveRequest,
headers: effectiveRequest.effectiveFinalHeaders.map((header) => ({
...header,
active: true,
})),
params: effectiveRequest.effectiveFinalParams.map((param) => ({
...param,
active: true,
})),
endpoint: effectiveRequest.effectiveFinalURL,
})
)
if (O.isSome(result)) {
errorState.value = false

View File

@@ -2,7 +2,7 @@ import * as Har from "har-format"
import { HoppRESTRequest } from "@hoppscotch/data"
import { FieldEquals, objectFieldIncludes } from "../typeutils"
// We support HAR Spec 1.2
// Hoppscotch support HAR Spec 1.2
// For more info on the spec: http://www.softwareishard.com/blog/har-12-spec/
const buildHarHeaders = (req: HoppRESTRequest): Har.Header[] => {
@@ -69,9 +69,6 @@ const buildHarPostParams = (
const buildHarPostData = (req: HoppRESTRequest): Har.PostData | undefined => {
if (!req.body.contentType) return undefined
if (!objectFieldIncludes(req, "method", ["POST", "PUT"] as const))
return undefined
if (
objectFieldIncludes(req.body, "contentType", [
"application/x-www-form-urlencoded",
@@ -82,13 +79,11 @@ const buildHarPostData = (req: HoppRESTRequest): Har.PostData | undefined => {
mimeType: req.body.contentType, // By default assume JSON ?
params: buildHarPostParams(req as any),
}
} else {
if (!req.body.contentType) return undefined
}
return {
mimeType: req.body.contentType, // Let's assume by default content type is JSON
text: req.body.body,
}
return {
mimeType: req.body.contentType, // Let's assume by default content type is JSON
text: req.body.body,
}
}