chore: update response original request version (#4555)
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
<LensesResponseBodyRenderer
|
||||
v-if="!loading && hasResponse"
|
||||
v-model:document="doc"
|
||||
:is-editable="false"
|
||||
@save-as-example="saveAsExample"
|
||||
/>
|
||||
</div>
|
||||
@@ -84,7 +85,7 @@ const onSaveAsExample = () => {
|
||||
} = response.req
|
||||
|
||||
const originalRequest: HoppRESTResponseOriginalRequest = {
|
||||
v: "1",
|
||||
v: "2",
|
||||
method,
|
||||
endpoint,
|
||||
headers,
|
||||
|
||||
@@ -47,7 +47,7 @@ const t = useI18n()
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
show: boolean
|
||||
loadingState: boolean
|
||||
loadingState?: boolean
|
||||
modelValue?: string
|
||||
}>(),
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
:info="`${maybeHeaders.length}`"
|
||||
class="flex flex-1 flex-col"
|
||||
>
|
||||
<LensesHeadersRenderer v-model="maybeHeaders" />
|
||||
<LensesHeadersRenderer v-model="maybeHeaders" :is-editable="false" />
|
||||
</HoppSmartTab>
|
||||
<HoppSmartTab
|
||||
v-if="!isEditable"
|
||||
|
||||
@@ -812,7 +812,7 @@ const convertPathToHoppReqs = (
|
||||
requestVariables: parseOpenAPIVariables(
|
||||
(info.parameters as OpenAPIParamsType[] | undefined) ?? []
|
||||
),
|
||||
v: "1",
|
||||
v: "2",
|
||||
}),
|
||||
}),
|
||||
metadata: {
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
import { stringArrayJoin } from "~/helpers/functional/array"
|
||||
import { PMRawLanguage } from "~/types/pm-coll-exts"
|
||||
import { IMPORTER_INVALID_FILE_FORMAT } from "."
|
||||
import { HoppRESTRequestResponses } from "@hoppscotch/data/dist/rest/v/8"
|
||||
import { HoppRESTRequestResponses } from "@hoppscotch/data"
|
||||
|
||||
const safeParseJSON = (jsonStr: string) => 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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -85,7 +85,7 @@ export const HoppRESTAuth = z
|
||||
|
||||
export type HoppRESTAuth = z.infer<typeof HoppRESTAuth>
|
||||
|
||||
const ValidCodes = z.union(
|
||||
export const ValidCodes = z.union(
|
||||
Object.keys(StatusCodes).map((code) => z.literal(parseInt(code))) as [
|
||||
z.ZodLiteral<number>,
|
||||
z.ZodLiteral<number>,
|
||||
@@ -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(),
|
||||
|
||||
@@ -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<typeof HoppRESTReqBody>
|
||||
|
||||
/**
|
||||
* 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<typeof HoppRESTRequestResponse>
|
||||
|
||||
/**
|
||||
* 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<typeof HoppRESTRequestResponses>
|
||||
|
||||
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<typeof V8_SCHEMA>) {
|
||||
// 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,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user