Skip to content

Commit 6693e1d

Browse files
authored
fix(joi)!: switch from @hapi/joi to joi (#284)
the `@hapi/joi` package is deprecated, and no longer receiving updates, switch to the replacement `joi` ref: - https://www.npmjs.com/package/@hapi/joi - https://www.npmjs.com/package/joi BREAKING CHANGE: `peerDependency` changed to `joi` for users of `--schema-builder joi`
1 parent 7b34fd4 commit 6693e1d

File tree

7 files changed

+65
-74
lines changed

7 files changed

+65
-74
lines changed

integration-tests/typescript-koa/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
"validate": "tsc -p ./tsconfig.json"
1111
},
1212
"dependencies": {
13-
"@hapi/joi": "^17.1.1",
1413
"@koa/router": "^13.1.0",
1514
"@nahkies/typescript-koa-runtime": "*",
16-
"@types/hapi__joi": "^17.1.15",
15+
"joi": "^17.13.3",
1716
"koa": "^2.15.3",
1817
"zod": "^3.23.8"
1918
},

packages/openapi-code-generator/src/typescript/common/schema-builders/joi-schema-builder.spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe.each(testVersions)(
2424
// I think it should be possible move loading of joi into the context, such that
2525
// it gets the contexts global RegExp correctly, but I can't figure it out right now.
2626

27-
{joi: require("@hapi/joi"), RegExp},
27+
{joi: require("joi"), RegExp},
2828
)
2929
}
3030

@@ -44,7 +44,7 @@ describe.each(testVersions)(
4444
`)
4545

4646
expect(schemas).toMatchInlineSnapshot(`
47-
"import joi from "@hapi/joi"
47+
"import joi from "joi"
4848
4949
export const s_SimpleObject = joi
5050
.object()
@@ -75,7 +75,7 @@ describe.each(testVersions)(
7575
`)
7676

7777
expect(schemas).toMatchInlineSnapshot(`
78-
"import joi from "@hapi/joi"
78+
"import joi from "joi"
7979
8080
export const s_AString = joi.string().required().id("s_AString")
8181
@@ -124,7 +124,7 @@ describe.each(testVersions)(
124124
`)
125125

126126
expect(schemas).toMatchInlineSnapshot(`
127-
"import joi from "@hapi/joi"
127+
"import joi from "joi"
128128
129129
export const s_OneOf = joi
130130
.alternatives()
@@ -152,7 +152,7 @@ describe.each(testVersions)(
152152
`)
153153

154154
expect(schemas).toMatchInlineSnapshot(`
155-
"import joi from "@hapi/joi"
155+
"import joi from "joi"
156156
157157
export const s_AnyOf = joi
158158
.alternatives()
@@ -172,7 +172,7 @@ describe.each(testVersions)(
172172
`)
173173

174174
expect(schemas).toMatchInlineSnapshot(`
175-
"import joi from "@hapi/joi"
175+
"import joi from "joi"
176176
177177
export const s_Base = joi
178178
.object()
@@ -205,7 +205,7 @@ describe.each(testVersions)(
205205
`)
206206

207207
expect(schemas).toMatchInlineSnapshot(`
208-
"import joi from "@hapi/joi"
208+
"import joi from "joi"
209209
210210
export const s_Recursive = joi
211211
.object()
@@ -226,7 +226,7 @@ describe.each(testVersions)(
226226
`)
227227

228228
expect(schemas).toMatchInlineSnapshot(`
229-
"import joi from "@hapi/joi"
229+
"import joi from "joi"
230230
231231
export const s_AOrdering = joi
232232
.object()
@@ -264,7 +264,7 @@ describe.each(testVersions)(
264264
`)
265265

266266
expect(schemas).toMatchInlineSnapshot(`
267-
"import joi from "@hapi/joi"
267+
"import joi from "joi"
268268
269269
export const s_Enums = joi
270270
.object()
@@ -291,7 +291,7 @@ describe.each(testVersions)(
291291
`)
292292

293293
expect(schemas).toMatchInlineSnapshot(`
294-
"import joi from "@hapi/joi"
294+
"import joi from "joi"
295295
296296
export const s_AdditionalPropertiesBool = joi
297297
.object()
@@ -313,7 +313,7 @@ describe.each(testVersions)(
313313
`)
314314

315315
expect(schemas).toMatchInlineSnapshot(`
316-
"import joi from "@hapi/joi"
316+
"import joi from "joi"
317317
318318
export const s_AdditionalPropertiesUnknownEmptySchema = joi
319319
.object()
@@ -335,7 +335,7 @@ describe.each(testVersions)(
335335
`)
336336

337337
expect(schemas).toMatchInlineSnapshot(`
338-
"import joi from "@hapi/joi"
338+
"import joi from "joi"
339339
340340
export const s_AdditionalPropertiesUnknownEmptyObjectSchema = joi
341341
.object()
@@ -357,7 +357,7 @@ describe.each(testVersions)(
357357
`)
358358

359359
expect(schemas).toMatchInlineSnapshot(`
360-
"import joi from "@hapi/joi"
360+
"import joi from "joi"
361361
362362
export const s_NamedNullableStringEnum = joi
363363
.string()
@@ -388,7 +388,7 @@ describe.each(testVersions)(
388388
`)
389389

390390
expect(schemas).toMatchInlineSnapshot(`
391-
"import joi from "@hapi/joi"
391+
"import joi from "joi"
392392
393393
export const s_AdditionalPropertiesMixed = joi
394394
.object()
@@ -449,7 +449,7 @@ describe.each(testVersions)(
449449
)
450450

451451
await expect(execute(5)).rejects.toThrow(
452-
'"value" must be larger than or equal to 10',
452+
'"value" must be greater than or equal to 10',
453453
)
454454
await expect(execute(20)).resolves.toBe(20)
455455
})
@@ -482,7 +482,7 @@ describe.each(testVersions)(
482482
)
483483

484484
await expect(execute(5)).rejects.toThrow(
485-
'"value" must be larger than or equal to 10',
485+
'"value" must be greater than or equal to 10',
486486
)
487487
await expect(execute(25)).rejects.toThrow(
488488
'"value" must be less than or equal to 24',
@@ -552,7 +552,7 @@ describe.each(testVersions)(
552552
'"value" must be a multiple of 4',
553553
)
554554
await expect(execute(8)).rejects.toThrow(
555-
'"value" must be larger than or equal to 10',
555+
'"value" must be greater than or equal to 10',
556556
)
557557
await expect(execute(24)).rejects.toThrow(
558558
'"value" must be less than or equal to 20',
@@ -571,7 +571,7 @@ describe.each(testVersions)(
571571
)
572572

573573
await expect(execute(-1)).rejects.toThrow(
574-
'"value" must be larger than or equal to 0',
574+
'"value" must be greater than or equal to 0',
575575
)
576576
})
577577

packages/openapi-code-generator/src/typescript/common/schema-builders/joi-schema-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class JoiBuilder extends AbstractSchemaBuilder<
4848
}
4949

5050
protected importHelpers(imports: ImportBuilder) {
51-
imports.addModule(joi, "@hapi/joi")
51+
imports.addModule(joi, "joi")
5252
}
5353

5454
public parse(schema: string, value: string): string {

packages/typescript-fetch-runtime/src/joi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Schema as JoiSchema} from "@hapi/joi"
1+
import type {Schema as JoiSchema} from "joi"
22
import type {Res, StatusCode} from "./main"
33

44
export function responseValidationFactory(

packages/typescript-koa-runtime/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@
4444
"test": "jest"
4545
},
4646
"peerDependencies": {
47-
"@hapi/joi": "^17.1.1",
4847
"@koa/cors": "^5.0.0",
4948
"@koa/router": "^13.0.0",
49+
"joi": "^17.1.1",
5050
"koa": "^2.14.1",
5151
"koa-body": "^6.0.1",
5252
"zod": "^3.20.6"
5353
},
5454
"devDependencies": {
55-
"@hapi/joi": "^17.1.1",
5655
"@koa/cors": "^5.0.0",
5756
"@koa/router": "^13.1.0",
5857
"@types/koa": "^2.15.0",
5958
"@types/koa__cors": "^5.0.0",
6059
"@types/koa__router": "^12.0.4",
6160
"jest": "^30.0.0-alpha.6",
61+
"joi": "^17.1.1",
6262
"koa": "^2.15.3",
6363
"koa-body": "^6.0.1",
6464
"typescript": "~5.7.2",

packages/typescript-koa-runtime/src/joi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Schema as JoiSchema} from "@hapi/joi"
1+
import type {Schema as JoiSchema} from "joi"
22
import {KoaRuntimeError, type RequestInputType} from "./errors"
33

44
export type Params<Params, Query, Body> = {

yarn.lock

Lines changed: 41 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)