diff --git a/packages/hoppscotch-common/src/components/http/Response.vue b/packages/hoppscotch-common/src/components/http/Response.vue
index 0869b32d2..466741ca5 100644
--- a/packages/hoppscotch-common/src/components/http/Response.vue
+++ b/packages/hoppscotch-common/src/components/http/Response.vue
@@ -4,6 +4,7 @@
@@ -84,7 +85,7 @@ const onSaveAsExample = () => {
} = response.req
const originalRequest: HoppRESTResponseOriginalRequest = {
- v: "1",
+ v: "2",
method,
endpoint,
headers,
diff --git a/packages/hoppscotch-common/src/components/http/SaveResponseName.vue b/packages/hoppscotch-common/src/components/http/SaveResponseName.vue
index 4ce36e2d5..431be738e 100644
--- a/packages/hoppscotch-common/src/components/http/SaveResponseName.vue
+++ b/packages/hoppscotch-common/src/components/http/SaveResponseName.vue
@@ -47,7 +47,7 @@ const t = useI18n()
const props = withDefaults(
defineProps<{
show: boolean
- loadingState: boolean
+ loadingState?: boolean
modelValue?: string
}>(),
{
diff --git a/packages/hoppscotch-common/src/components/lenses/ResponseBodyRenderer.vue b/packages/hoppscotch-common/src/components/lenses/ResponseBodyRenderer.vue
index 7a496f109..061cf897b 100644
--- a/packages/hoppscotch-common/src/components/lenses/ResponseBodyRenderer.vue
+++ b/packages/hoppscotch-common/src/components/lenses/ResponseBodyRenderer.vue
@@ -26,7 +26,7 @@
:info="`${maybeHeaders.length}`"
class="flex flex-1 flex-col"
>
-
+
O.tryCatch(() => JSON.parse(jsonStr))
@@ -177,7 +177,7 @@ const getHoppResponses = (
requestVariables: getHoppReqVariables(
response.originalRequest?.url.variables ?? null
),
- v: "1" as const,
+ v: "2" as const,
},
}
return [response.name, res]
diff --git a/packages/hoppscotch-data/src/rest/index.ts b/packages/hoppscotch-data/src/rest/index.ts
index 80c7b02e1..a06c68a95 100644
--- a/packages/hoppscotch-data/src/rest/index.ts
+++ b/packages/hoppscotch-data/src/rest/index.ts
@@ -14,8 +14,8 @@ import V4_VERSION from "./v/4"
import V5_VERSION from "./v/5"
import V6_VERSION from "./v/6"
import V7_VERSION, { HoppRESTHeaders, HoppRESTParams } from "./v/7"
-import V8_VERSION, { HoppRESTAuth, HoppRESTRequestResponses } from "./v/8"
-import V9_VERSION, { HoppRESTReqBody } from "./v/9"
+import V8_VERSION, { HoppRESTAuth } from "./v/8"
+import V9_VERSION, { HoppRESTReqBody, HoppRESTRequestResponses } from "./v/9"
export * from "./content-types"
@@ -46,12 +46,15 @@ export {
HoppRESTAuthOAuth2,
HoppRESTAuthDigest,
PasswordGrantTypeParams,
+} from "./v/8"
+
+export {
+ FormDataKeyValue,
+ HoppRESTReqBody,
HoppRESTResponseOriginalRequest,
HoppRESTRequestResponse,
HoppRESTRequestResponses,
-} from "./v/8"
-
-export { FormDataKeyValue, HoppRESTReqBody } from "./v/9"
+} from "./v/9"
const versionedObject = z.object({
// v is a stringified number
diff --git a/packages/hoppscotch-data/src/rest/v/8.ts b/packages/hoppscotch-data/src/rest/v/8.ts
index 5b34eba5f..6e047cb54 100644
--- a/packages/hoppscotch-data/src/rest/v/8.ts
+++ b/packages/hoppscotch-data/src/rest/v/8.ts
@@ -85,7 +85,7 @@ export const HoppRESTAuth = z
export type HoppRESTAuth = z.infer
-const ValidCodes = z.union(
+export const ValidCodes = z.union(
Object.keys(StatusCodes).map((code) => z.literal(parseInt(code))) as [
z.ZodLiteral,
z.ZodLiteral,
@@ -93,7 +93,7 @@ const ValidCodes = z.union(
]
)
-const HoppRESTResponseHeaders = z.array(
+export const HoppRESTResponseHeaders = z.array(
z.object({
key: z.string(),
value: z.string(),
diff --git a/packages/hoppscotch-data/src/rest/v/9.ts b/packages/hoppscotch-data/src/rest/v/9.ts
index 717d4e72f..be20eaf6f 100644
--- a/packages/hoppscotch-data/src/rest/v/9.ts
+++ b/packages/hoppscotch-data/src/rest/v/9.ts
@@ -1,7 +1,14 @@
import { defineVersion } from "verzod"
import { z } from "zod"
-import { V8_SCHEMA } from "./8"
+import { HoppRESTRequestVariables } from "./2"
+import { HoppRESTHeaders, HoppRESTParams } from "./7"
+import {
+ HoppRESTAuth,
+ HoppRESTResponseHeaders,
+ V8_SCHEMA,
+ ValidCodes,
+} from "./8"
export const FormDataKeyValue = z
.object({
@@ -52,19 +59,78 @@ export const HoppRESTReqBody = z.union([
export type HoppRESTReqBody = z.infer
+/**
+ * The original request that was made to get this response
+ * Only the necessary fields are saved
+ */
+export const HoppRESTResponseOriginalRequest = z.object({
+ v: z.literal("2"),
+ name: z.string(),
+ method: z.string(),
+ endpoint: z.string(),
+ headers: HoppRESTHeaders,
+ params: HoppRESTParams,
+ body: HoppRESTReqBody,
+ auth: HoppRESTAuth,
+ requestVariables: HoppRESTRequestVariables,
+})
+
+export type HoppRESTResponseOriginalRequest = z.infer<
+ typeof HoppRESTResponseOriginalRequest
+>
+
+export const HoppRESTRequestResponse = z.object({
+ name: z.string(),
+ originalRequest: HoppRESTResponseOriginalRequest,
+ status: z.string(),
+ code: z.optional(ValidCodes),
+ headers: HoppRESTResponseHeaders,
+ body: z.string(),
+})
+
+export type HoppRESTRequestResponse = z.infer
+
+/**
+ * The responses saved for a request
+ * The key is the name of the response saved by the user
+ * The value is the response
+ */
+export const HoppRESTRequestResponses = z.record(
+ z.string(),
+ HoppRESTRequestResponse
+)
+
+export type HoppRESTRequestResponses = z.infer
+
export const V9_SCHEMA = V8_SCHEMA.extend({
v: z.literal("9"),
body: HoppRESTReqBody,
+ responses: HoppRESTRequestResponses,
})
export default defineVersion({
schema: V9_SCHEMA,
initial: false,
up(old: z.infer) {
- // No migration, the new contentType added to each formdata field is optional
+ // update the version number of response original request
+ const responses = Object.fromEntries(
+ Object.entries(old.responses).map(([key, response]) => [
+ key,
+ {
+ ...response,
+ originalRequest: {
+ ...response.originalRequest,
+ v: "2" as const,
+ },
+ },
+ ])
+ )
+
+ // No migration for body, the new contentType added to each formdata field is optional
return {
...old,
v: "9" as const,
+ responses,
}
},
})