fix(zod-openapi): return type of handler should be MaybePromise (#522)
* fix(zod-openapi): return type of handler should be MaybePromise * revert: changes * Create modern-buttons-impress.md * fix: typespull/523/head
parent
c5001c01e7
commit
2d5ef82558
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@hono/zod-openapi": patch
|
||||
---
|
||||
|
||||
fix(zod-openapi): return type of handler should be MaybePromise
|
|
@ -27,12 +27,14 @@ import type {
|
|||
TypedResponse,
|
||||
} from 'hono'
|
||||
import type { MergePath, MergeSchemaPath } from 'hono/types'
|
||||
import { StatusCode } from 'hono/utils/http-status'
|
||||
import type { StatusCode } from 'hono/utils/http-status'
|
||||
import type { Prettify, RemoveBlankRecord } from 'hono/utils/types'
|
||||
import { mergePath } from 'hono/utils/url'
|
||||
import type { AnyZodObject, ZodSchema, ZodError } from 'zod'
|
||||
import { z, ZodType } from 'zod'
|
||||
|
||||
type MaybePromise<T> = Promise<T> | T
|
||||
|
||||
type RouteConfig = RouteConfigBase & {
|
||||
middleware?: MiddlewareHandler | MiddlewareHandler[]
|
||||
}
|
||||
|
@ -290,8 +292,8 @@ export class OpenAPIHono<
|
|||
}
|
||||
}
|
||||
}
|
||||
? RouteConfigToTypedResponse<R>
|
||||
: RouteConfigToTypedResponse<R> | Response | Promise<Response>
|
||||
? MaybePromise<RouteConfigToTypedResponse<R>>
|
||||
: MaybePromise<RouteConfigToTypedResponse<R>> | MaybePromise<Response>
|
||||
>,
|
||||
hook:
|
||||
| Hook<
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
import { OpenAPIHono, createRoute, z } from '../src'
|
||||
|
||||
test('supports async handler', () => {
|
||||
const hono = new OpenAPIHono()
|
||||
|
||||
const route = createRoute({
|
||||
method: 'get',
|
||||
path: '/users',
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: z.object({
|
||||
id: z.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: 'Retrieve the user',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
hono.openapi(route, (c) => {
|
||||
return c.json({
|
||||
id: '123',
|
||||
})
|
||||
})
|
||||
|
||||
hono.openapi(route, async (c) => {
|
||||
return c.json({
|
||||
id: '123',
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue