Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix: issues with har generation
Andrew Bastinc3aedac77e6b
diff --git a/packages/hoppscotch-app/components/http/CodegenModal.vue b/packages/hoppscotch-app/components/http/CodegenModal.vueindex 9901aed48..175162eaa 100644--- a/packages/hoppscotch-app/components/http/CodegenModal.vue+++ b/packages/hoppscotch-app/components/http/CodegenModal.vue@@ -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 = falsediff --git a/packages/hoppscotch-app/helpers/new-codegen/har.ts b/packages/hoppscotch-app/helpers/new-codegen/har.tsindex d8e1bdfcc..04b81f59e 100644--- a/packages/hoppscotch-app/helpers/new-codegen/har.ts+++ b/packages/hoppscotch-app/helpers/new-codegen/har.ts@@ -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,}}