fix(zod-openapi): infer Env correctly if the middleware is `[]` (#1106)
* fix(zod-openapi): infer Env correctly if the middleware is `[]` * add changesetpull/1107/head
parent
f349fba499
commit
448a8fc687
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@hono/zod-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: infer Env correctly if the middleware is `[]`
|
|
@ -337,4 +337,25 @@ describe('Middleware', () => {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should infer Env correctly when the middleware is empty', async () => {
|
||||||
|
const app = new OpenAPIHono<{ Variables: { foo: string } }>()
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
method: 'get',
|
||||||
|
path: '/books',
|
||||||
|
middleware: [] as const, // empty
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'response',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
(c) => {
|
||||||
|
const foo = c.get('foo')
|
||||||
|
type verify = Expect<Equal<typeof foo, string>>
|
||||||
|
return c.json({})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -305,7 +305,7 @@ export type MiddlewareToHandlerType<M extends MiddlewareHandler<any, any, any>[]
|
||||||
: never
|
: never
|
||||||
: M extends [infer Last]
|
: M extends [infer Last]
|
||||||
? Last // Return the last remaining handler in the array
|
? Last // Return the last remaining handler in the array
|
||||||
: never
|
: MiddlewareHandler<Env>
|
||||||
|
|
||||||
type RouteMiddlewareParams<R extends RouteConfig> = OfHandlerType<
|
type RouteMiddlewareParams<R extends RouteConfig> = OfHandlerType<
|
||||||
MiddlewareToHandlerType<AsArray<R['middleware']>>
|
MiddlewareToHandlerType<AsArray<R['middleware']>>
|
||||||
|
|
|
@ -2,9 +2,14 @@
|
||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "../../dist/out-tsc/packages/zod-openapi",
|
"outDir": "../../dist/out-tsc/packages/zod-openapi",
|
||||||
"types": ["vitest/globals"]
|
"types": [
|
||||||
|
"vitest/globals"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"include": ["**/*.test.ts"],
|
"include": [
|
||||||
|
"**/*.test.ts",
|
||||||
|
"**/*.test-d.ts"
|
||||||
|
],
|
||||||
"references": [
|
"references": [
|
||||||
{
|
{
|
||||||
"path": "./tsconfig.build.json"
|
"path": "./tsconfig.build.json"
|
||||||
|
|
Loading…
Reference in New Issue