Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: improved codegen compat

Andrew Bastinf5c84b57b22a
diff --git a/components/http/CodegenModal.vue b/components/http/CodegenModal.vue
index dc8e02cbc..71f1ef641 100644
--- a/components/http/CodegenModal.vue
+++ b/components/http/CodegenModal.vue
@@ -1,7 +1,7 @@
<template>
<SmartModal
v-if="show"
- :title="$t('request.generate_code')"
+ :title="t('request.generate_code')"
@close="hideModal"
>
<template #body>
@@ -35,7 +35,7 @@
</tippy>
<div class="flex flex-1 justify-between">
<label for="generatedCode" class="px-4 pt-4 pb-4">
- {{ $t("request.generated_code") }}
+ {{ t("request.generated_code") }}
</label>
</div>
<SmartAceEditor
@@ -58,14 +58,11 @@
<template #footer>
<ButtonPrimary
ref="copyRequestCode"
- :label="$t('action.copy')"
+ :label="t('action.copy')"
:icon="copyIcon"
@click.native="copyRequestCode"
/>
- <ButtonSecondary
- :label="$t('action.dismiss')"
- @click.native="hideModal"
- />
+ <ButtonSecondary :label="t('action.dismiss')" @click.native="hideModal" />
</template>
</SmartModal>
</template>
@@ -90,7 +87,7 @@ const {
$toast,
app: { i18n },
} = useContext()
-const $t = i18n.t.bind(i18n)
+const t = i18n.t.bind(i18n)
const options = ref<any | null>(null)
@@ -123,7 +120,7 @@ const hideModal = () => emit("hide-modal")
const copyRequestCode = () => {
copyToClipboard(requestCode.value)
copyIcon.value = "done"
- $toast.success($t("state.copied_to_clipboard").toString(), {
+ $toast.success(t("state.copied_to_clipboard").toString(), {
icon: "content_paste",
})
setTimeout(() => (copyIcon.value = "content_copy"), 1000)
diff --git a/helpers/codegen/codegen.ts b/helpers/codegen/codegen.ts
index 81c257c73..ab6d21d8f 100644
--- a/helpers/codegen/codegen.ts
+++ b/helpers/codegen/codegen.ts
@@ -75,7 +75,7 @@ export type HoppCodegenContext = {
bodyParams: FormDataKeyValue[]
rawParams: string | null
rawInput: boolean
- rawRequestBody: any
+ rawRequestBody: string | null
contentType: string | null
queryString: string
}
@@ -138,6 +138,9 @@ function getCodegenGeneralRESTInfo(
| "headers"
> {
const urlObj = new URL(request.effectiveFinalURL)
+ request.effectiveFinalParams.forEach(({ key, value }) => {
+ urlObj.searchParams.append(key, value)
+ })
return {
name: request.name,
@@ -168,7 +171,10 @@ function getCodegenReqBodyData(
request.body.contentType === "multipart/form-data"
? request.body.body
: [],
- rawParams: null,
+ rawParams:
+ request.body.contentType !== "multipart/form-data"
+ ? request.body.body
+ : null,
}
}