fix(zod-openapi): update RouteHandler type to support MaybePromise (#529)
* fix(zod-openapi): update RouteHandler type to support MaybePromise * add .changeset/cuddly-pets-drum.mdpull/530/head
parent
cd0a2ce6c0
commit
0a43d2c562
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@hono/zod-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(zod-openapi): update RouteHandler type to support MaybePromise
|
|
@ -197,8 +197,8 @@ export type RouteHandler<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
? RouteConfigToTypedResponse<R>
|
? MaybePromise<RouteConfigToTypedResponse<R>>
|
||||||
: RouteConfigToTypedResponse<R> | Response | Promise<Response>
|
: MaybePromise<RouteConfigToTypedResponse<R>> | MaybePromise<Response>
|
||||||
>
|
>
|
||||||
|
|
||||||
export type RouteHook<
|
export type RouteHook<
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
import type { RouteHandler } from '../src'
|
||||||
import { OpenAPIHono, createRoute, z } from '../src'
|
import { OpenAPIHono, createRoute, z } from '../src'
|
||||||
|
|
||||||
test('supports async handler', () => {
|
describe('supports async handler', () => {
|
||||||
const hono = new OpenAPIHono()
|
|
||||||
|
|
||||||
const route = createRoute({
|
const route = createRoute({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: '/users',
|
path: '/users',
|
||||||
|
@ -20,6 +19,9 @@ test('supports async handler', () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('argument of openapi method', () => {
|
||||||
|
const hono = new OpenAPIHono()
|
||||||
|
|
||||||
hono.openapi(route, (c) => {
|
hono.openapi(route, (c) => {
|
||||||
return c.json({
|
return c.json({
|
||||||
id: '123',
|
id: '123',
|
||||||
|
@ -31,4 +33,23 @@ test('supports async handler', () => {
|
||||||
id: '123',
|
id: '123',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('RouteHandler type', () => {
|
||||||
|
const handler: RouteHandler<typeof route> = (c) => {
|
||||||
|
return c.json({
|
||||||
|
id: '123',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const asyncHandler: RouteHandler<typeof route> = async (c) => {
|
||||||
|
return c.json({
|
||||||
|
id: '123',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const hono = new OpenAPIHono()
|
||||||
|
hono.openapi(route, handler)
|
||||||
|
hono.openapi(route, asyncHandler)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue