feat(zod-openapi): support Zod v4
parent
44b1c24b95
commit
bdd25f2056
|
@ -40,7 +40,7 @@
|
|||
"homepage": "https://github.com/honojs/middleware",
|
||||
"peerDependencies": {
|
||||
"hono": ">=4.3.6",
|
||||
"zod": "3.*"
|
||||
"zod": "^3.25.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@arethetypeswrong/cli": "^0.17.4",
|
||||
|
@ -49,10 +49,10 @@
|
|||
"typescript": "^5.8.2",
|
||||
"vitest": "^3.0.8",
|
||||
"yaml": "^2.4.3",
|
||||
"zod": "^3.22.1"
|
||||
"zod": "^3.25.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@asteasolutions/zod-to-openapi": "^7.3.0",
|
||||
"@asteasolutions/zod-to-openapi": "^8.0.0-beta.3",
|
||||
"@hono/zod-validator": "workspace:^"
|
||||
},
|
||||
"engines": {
|
||||
|
|
|
@ -240,7 +240,7 @@ describe('coerce', () => {
|
|||
type Actual = ExtractSchema<typeof routes>['/api/users/:id']['$get']['input']
|
||||
type Expected = {
|
||||
param: {
|
||||
id: number
|
||||
id: unknown
|
||||
}
|
||||
}
|
||||
type verify = Expect<Equal<Expected, Actual>>
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
OpenApiGeneratorV3,
|
||||
OpenApiGeneratorV31,
|
||||
extendZodWithOpenApi,
|
||||
getOpenApiMetadata,
|
||||
} from '@asteasolutions/zod-to-openapi'
|
||||
import { zValidator } from '@hono/zod-validator'
|
||||
import { Hono } from 'hono'
|
||||
|
@ -36,8 +37,8 @@ import type {
|
|||
} from 'hono/utils/http-status'
|
||||
import type { JSONParsed, JSONValue, RemoveBlankRecord, SimplifyDeepArray } from 'hono/utils/types'
|
||||
import { mergePath } from 'hono/utils/url'
|
||||
import type { ZodError, ZodSchema } from 'zod'
|
||||
import { ZodType, z } from 'zod'
|
||||
import type { ZodError } from 'zod/v4'
|
||||
import { ZodType, z } from 'zod/v4'
|
||||
|
||||
type MaybePromise<T> = Promise<T> | T
|
||||
|
||||
|
@ -126,7 +127,7 @@ type InputTypeJson<R extends RouteConfig> = R['request'] extends RequestTypes
|
|||
? {}
|
||||
: R['request']['body']['content'][keyof R['request']['body']['content']] extends Record<
|
||||
'schema',
|
||||
ZodSchema<any>
|
||||
ZodType<any>
|
||||
>
|
||||
? {
|
||||
in: {
|
||||
|
@ -152,7 +153,7 @@ type InputTypeForm<R extends RouteConfig> = R['request'] extends RequestTypes
|
|||
? {}
|
||||
: R['request']['body']['content'][keyof R['request']['body']['content']] extends Record<
|
||||
'schema',
|
||||
ZodSchema<any>
|
||||
ZodType<any>
|
||||
>
|
||||
? {
|
||||
in: {
|
||||
|
@ -179,7 +180,7 @@ type InputTypeCookie<R extends RouteConfig> = InputTypeBase<R, 'cookies', 'cooki
|
|||
type ExtractContent<T> = T extends {
|
||||
[K in keyof T]: infer A
|
||||
}
|
||||
? A extends Record<'schema', ZodSchema>
|
||||
? A extends Record<'schema', ZodType>
|
||||
? z.infer<A['schema']>
|
||||
: never
|
||||
: never
|
||||
|
@ -520,6 +521,7 @@ export class OpenAPIHono<
|
|||
}
|
||||
}
|
||||
if (isFormContentType(mediaType)) {
|
||||
// @ts-expect-error The current zValidator does not accept ZodType
|
||||
const validator = zValidator('form', schema, hook as any)
|
||||
if (route.request?.body?.required) {
|
||||
validators.push(validator)
|
||||
|
@ -657,11 +659,14 @@ export class OpenAPIHono<
|
|||
})
|
||||
|
||||
case 'schema':
|
||||
return this.openAPIRegistry.register(def.schema._def.openapi._internal.refId, def.schema)
|
||||
return this.openAPIRegistry.register(
|
||||
getOpenApiMetadata(def.schema)._internal?.refId,
|
||||
def.schema
|
||||
)
|
||||
|
||||
case 'parameter':
|
||||
return this.openAPIRegistry.registerParameter(
|
||||
def.schema._def.openapi._internal.refId,
|
||||
getOpenApiMetadata(def.schema)._internal?.refId,
|
||||
def.schema
|
||||
)
|
||||
|
||||
|
|
25
yarn.lock
25
yarn.lock
|
@ -99,14 +99,14 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@asteasolutions/zod-to-openapi@npm:^7.3.0":
|
||||
version: 7.3.0
|
||||
resolution: "@asteasolutions/zod-to-openapi@npm:7.3.0"
|
||||
"@asteasolutions/zod-to-openapi@npm:^8.0.0-beta.3":
|
||||
version: 8.0.0-beta.3
|
||||
resolution: "@asteasolutions/zod-to-openapi@npm:8.0.0-beta.3"
|
||||
dependencies:
|
||||
openapi3-ts: "npm:^4.1.2"
|
||||
peerDependencies:
|
||||
zod: ^3.20.2
|
||||
checksum: 10c0/f0a68a89929cdeaa3e21d2027489689f982824d676a9332c680e119f60881dd39b571324b24ad4837fda49bf6fe7c3e2af2199268b281bf1aec923d7a7cbfc40
|
||||
zod: ~3.25.1
|
||||
checksum: 10c0/73e9554ca4650bd7daa2cb4a66763e81e6d60a39c429db206e5c4bbd081ffbe6fac998b50a7b1e8ded4ca71b9629fafb8eadce4588d7fad89c1177869b2a35b7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
@ -2379,17 +2379,17 @@ __metadata:
|
|||
resolution: "@hono/zod-openapi@workspace:packages/zod-openapi"
|
||||
dependencies:
|
||||
"@arethetypeswrong/cli": "npm:^0.17.4"
|
||||
"@asteasolutions/zod-to-openapi": "npm:^7.3.0"
|
||||
"@asteasolutions/zod-to-openapi": "npm:^8.0.0-beta.3"
|
||||
"@hono/zod-validator": "workspace:^"
|
||||
publint: "npm:^0.3.9"
|
||||
tsup: "npm:^8.4.0"
|
||||
typescript: "npm:^5.8.2"
|
||||
vitest: "npm:^3.0.8"
|
||||
yaml: "npm:^2.4.3"
|
||||
zod: "npm:^3.22.1"
|
||||
zod: "npm:^3.25.0"
|
||||
peerDependencies:
|
||||
hono: ">=4.3.6"
|
||||
zod: 3.*
|
||||
zod: ^3.25.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
|
@ -15153,7 +15153,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"zod@npm:^3.20.2, zod@npm:^3.22.1, zod@npm:^3.22.3":
|
||||
"zod@npm:^3.20.2, zod@npm:^3.22.3":
|
||||
version: 3.24.2
|
||||
resolution: "zod@npm:3.24.2"
|
||||
checksum: 10c0/c638c7220150847f13ad90635b3e7d0321b36cce36f3fc6050ed960689594c949c326dfe2c6fa87c14b126ee5d370ccdebd6efb304f41ef5557a4aaca2824565
|
||||
|
@ -15174,6 +15174,13 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"zod@npm:^3.25.0":
|
||||
version: 3.25.64
|
||||
resolution: "zod@npm:3.25.64"
|
||||
checksum: 10c0/00d76093a999e377e4ffd037fa7185e861c35917e8c4272f514115c206a0654995168f57fb71708b11e0a9243206d988b7f63b543404e1796402e50d346a6bd7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"zod@npm:~3.25.6":
|
||||
version: 3.25.36
|
||||
resolution: "zod@npm:3.25.36"
|
||||
|
|
Loading…
Reference in New Issue