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,
|
TypedResponse,
|
||||||
} from 'hono'
|
} from 'hono'
|
||||||
import type { MergePath, MergeSchemaPath } from 'hono/types'
|
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 type { Prettify, RemoveBlankRecord } from 'hono/utils/types'
|
||||||
import { mergePath } from 'hono/utils/url'
|
import { mergePath } from 'hono/utils/url'
|
||||||
import type { AnyZodObject, ZodSchema, ZodError } from 'zod'
|
import type { AnyZodObject, ZodSchema, ZodError } from 'zod'
|
||||||
import { z, ZodType } from 'zod'
|
import { z, ZodType } from 'zod'
|
||||||
|
|
||||||
|
type MaybePromise<T> = Promise<T> | T
|
||||||
|
|
||||||
type RouteConfig = RouteConfigBase & {
|
type RouteConfig = RouteConfigBase & {
|
||||||
middleware?: MiddlewareHandler | MiddlewareHandler[]
|
middleware?: MiddlewareHandler | MiddlewareHandler[]
|
||||||
}
|
}
|
||||||
|
@ -290,8 +292,8 @@ export class OpenAPIHono<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
? RouteConfigToTypedResponse<R>
|
? MaybePromise<RouteConfigToTypedResponse<R>>
|
||||||
: RouteConfigToTypedResponse<R> | Response | Promise<Response>
|
: MaybePromise<RouteConfigToTypedResponse<R>> | MaybePromise<Response>
|
||||||
>,
|
>,
|
||||||
hook:
|
hook:
|
||||||
| 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