Skip to content

Commit 805ac88

Browse files
authored
fix: environment and rest tab state schema migration (hoppscotch#5105)
1 parent 052dc17 commit 805ac88

File tree

15 files changed

+190
-51
lines changed

15 files changed

+190
-51
lines changed

packages/hoppscotch-common/src/components/http/Response.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { getStatusCodeReasonPhrase } from "~/helpers/utils/statusCodes"
2626
import {
2727
HoppRESTResponseOriginalRequest,
2828
HoppRESTRequestResponse,
29+
RESTResOriginalReqSchemaVersion,
2930
} from "@hoppscotch/data"
3031
import { editRESTRequest } from "~/newstore/collections"
3132
import { useToast } from "@composables/toast"
@@ -94,7 +95,7 @@ const onSaveAsExample = () => {
9495
} = response.req
9596
9697
const originalRequest: HoppRESTResponseOriginalRequest = {
97-
v: "3",
98+
v: RESTResOriginalReqSchemaVersion,
9899
method,
99100
endpoint,
100101
headers,

packages/hoppscotch-common/src/helpers/import-export/import/insomniaEnv.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import * as O from "fp-ts/Option"
44
import { IMPORTER_INVALID_FILE_FORMAT } from "."
55

66
import { z } from "zod"
7-
import { NonSecretEnvironment } from "@hoppscotch/data"
7+
import {
8+
EnvironmentSchemaVersion,
9+
NonSecretEnvironment,
10+
} from "@hoppscotch/data"
811
import { safeParseJSONOrYAML } from "~/helpers/functional/yaml"
912
import { uniqueID } from "~/helpers/utils/uniqueID"
1013

@@ -67,13 +70,13 @@ export const insomniaEnvImporter = (contents: string[]) => {
6770
if (parsedInsomniaEnv.success) {
6871
const environment: NonSecretEnvironment = {
6972
id: uniqueID(),
70-
v: 2,
73+
v: EnvironmentSchemaVersion,
7174
name: parsedInsomniaEnv.data.name,
7275
variables: Object.entries(parsedInsomniaEnv.data.data).map(
7376
([key, value]) => ({
7477
key,
7578
initialValue: value,
76-
currentValue: value,
79+
currentValue: "",
7780
secret: false,
7881
})
7982
),

packages/hoppscotch-common/src/helpers/import-export/import/openapi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
HoppRESTRequest,
2121
HoppRESTRequestResponses,
2222
HoppRESTResponseOriginalRequest,
23+
RESTResOriginalReqSchemaVersion,
2324
} from "@hoppscotch/data"
2425
import { pipe, flow } from "fp-ts/function"
2526
import * as A from "fp-ts/Array"
@@ -843,7 +844,7 @@ const convertPathToHoppReqs = (
843844
requestVariables: parseOpenAPIVariables(
844845
(info.parameters as OpenAPIParamsType[] | undefined) ?? []
845846
),
846-
v: "3",
847+
v: RESTResOriginalReqSchemaVersion,
847848
}),
848849
}),
849850
metadata: {

packages/hoppscotch-common/src/helpers/import-export/import/postman.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
knownContentTypes,
1111
makeCollection,
1212
makeRESTRequest,
13+
RESTResOriginalReqSchemaVersion,
1314
ValidContentTypes,
1415
} from "@hoppscotch/data"
1516
import * as A from "fp-ts/Array"
@@ -177,7 +178,7 @@ const getHoppResponses = (
177178
requestVariables: getHoppReqVariables(
178179
response.originalRequest?.url.variables ?? null
179180
),
180-
v: "3" as const,
181+
v: RESTResOriginalReqSchemaVersion,
181182
},
182183
}
183184
return [response.name, res]

packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Environment } from "@hoppscotch/data"
1+
import { Environment, EnvironmentSchemaVersion } from "@hoppscotch/data"
22
import * as O from "fp-ts/Option"
33
import * as TE from "fp-ts/TaskEither"
44
import { z } from "zod"
@@ -52,12 +52,12 @@ export const postmanEnvImporter = (contents: string[]) => {
5252
const environments: Environment[] = validationResult.data.map(
5353
({ name, values }) => ({
5454
id: uniqueID(),
55-
v: 2,
55+
v: EnvironmentSchemaVersion,
5656
name,
5757
variables: values.map(({ key, value, type }) => ({
5858
key,
5959
initialValue: value,
60-
currentValue: value,
60+
currentValue: "",
6161
secret: type === "secret",
6262
})),
6363
})

packages/hoppscotch-common/src/helpers/teams/TeamEnvironmentAdapter.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
TeamEnvironmentUpdatedDocument,
1111
} from "../backend/graphql"
1212
import { TeamEnvironment } from "./TeamEnvironment"
13+
import { Environment, EnvironmentSchemaVersion } from "@hoppscotch/data"
14+
import { entityReference } from "verzod"
1315

1416
type EntityType = "environment"
1517
type EntityID = `${EntityType}-${string}`
@@ -112,19 +114,27 @@ export default class TeamEnvironmentAdapter {
112114

113115
if (result.right.team) {
114116
results.push(
115-
...result.right.team.teamEnvironments.map(
116-
(x) =>
117-
<TeamEnvironment>{
118-
id: x.id,
119-
teamID: x.teamID,
120-
environment: {
121-
v: 2,
122-
id: x.id,
123-
name: x.name,
124-
variables: JSON.parse(x.variables),
125-
},
126-
}
127-
)
117+
...result.right.team.teamEnvironments.map((x) => {
118+
const environment = <Environment>{
119+
id: x.id,
120+
name: x.name,
121+
variables: JSON.parse(x.variables),
122+
}
123+
124+
const parsedEnvironment =
125+
entityReference(Environment).safeParse(environment)
126+
127+
return <TeamEnvironment>{
128+
id: x.id,
129+
teamID: x.teamID,
130+
environment: parsedEnvironment.success
131+
? parsedEnvironment.data
132+
: {
133+
...environment,
134+
v: EnvironmentSchemaVersion,
135+
},
136+
}
137+
})
128138
)
129139
}
130140

packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ const HoppTestResultSchema = z
433433
.strict(),
434434
})
435435
.strict(),
436-
consoleEntries: z.array(z.record(z.string(), z.unknown()).optional()),
436+
consoleEntries: z.optional(z.array(z.record(z.string(), z.unknown()))),
437437
})
438438
.strict()
439439

packages/hoppscotch-data/src/environment/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export const translateToNewEnvironmentVariables = (
204204
return {
205205
key: x.key,
206206
initialValue: x.initialValue ?? x.value ?? "",
207-
currentValue: x.currentValue ?? x.value ?? "",
207+
currentValue: "",
208208
secret: false,
209209
}
210210
}

packages/hoppscotch-data/src/environment/v/2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default defineVersion({
3232
key,
3333
secret,
3434
initialValue: secret ? "" : variable.value,
35-
currentValue: secret ? "" : variable.value,
35+
currentValue: "",
3636
}
3737
}),
3838
}

packages/hoppscotch-data/src/rest/index.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import V7_VERSION, { HoppRESTHeaders, HoppRESTParams } from "./v/7"
1717
import V8_VERSION from "./v/8"
1818
import V9_VERSION from "./v/9"
1919
import V10_VERSION, { HoppRESTReqBody } from "./v/10"
20-
import V11_VERSION, { HoppRESTRequestResponses } from "./v/11"
20+
import V11_VERSION from "./v/11"
2121
import V12_VERSION from "./v/12"
22-
import V13_VERSION, { HoppRESTAuth } from "./v/13"
22+
import V13_VERSION, { HoppRESTAuth, HoppRESTRequestResponses } from "./v/13"
2323

2424
export * from "./content-types"
2525

@@ -48,19 +48,19 @@ export { HoppRESTAuthDigest, PasswordGrantTypeParams } from "./v/8"
4848

4949
export { FormDataKeyValue } from "./v/9"
5050

51-
export {
52-
HoppRESTResponseOriginalRequest,
53-
HoppRESTRequestResponse,
54-
HoppRESTRequestResponses,
55-
HoppRESTAuthOAuth2,
56-
ClientCredentialsGrantTypeParams,
57-
} from "./v/11"
51+
export { HoppRESTAuthOAuth2, ClientCredentialsGrantTypeParams } from "./v/11"
5852

5953
export { HoppRESTReqBody } from "./v/10"
6054

6155
export { HoppRESTAuthHAWK, HoppRESTAuthAkamaiEdgeGrid } from "./v/12"
6256

63-
export { HoppRESTAuth, HoppRESTAuthJWT } from "./v/13"
57+
export {
58+
HoppRESTAuth,
59+
HoppRESTAuthJWT,
60+
HoppRESTRequestResponses,
61+
HoppRESTResponseOriginalRequest,
62+
HoppRESTRequestResponse,
63+
} from "./v/13"
6464

6565
const versionedObject = z.object({
6666
// v is a stringified number
@@ -127,6 +127,7 @@ const HoppRESTRequestEq = Eq.struct<HoppRESTRequest>({
127127
})
128128

129129
export const RESTReqSchemaVersion = "13"
130+
export const RESTResOriginalReqSchemaVersion = "5" as const
130131

131132
export type HoppRESTParam = HoppRESTRequest["params"][number]
132133
export type HoppRESTHeader = HoppRESTRequest["headers"][number]

0 commit comments

Comments
 (0)