fix(zod-openapi): Fix basePath method to transfer defaultHook of the parent app. (#408)
* Fix basePath method to transfer defaultHook of the parent app. * Revert back variable typing * Add changeset for @hono/zod-openapipull/409/head
parent
5c0d4adf62
commit
d4ca1ce98f
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@hono/zod-openapi': patch
|
||||
---
|
||||
|
||||
fix: Fix basePath method disregarding defaultHook
|
|
@ -409,7 +409,7 @@ export class OpenAPIHono<
|
|||
}
|
||||
|
||||
basePath<SubPath extends string>(path: SubPath): OpenAPIHono<E, S, MergePath<BasePath, SubPath>> {
|
||||
return new OpenAPIHono(super.basePath(path) as any)
|
||||
return new OpenAPIHono({...super.basePath(path) as any, defaultHook: this.defaultHook})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -823,6 +823,15 @@ describe('basePath()', () => {
|
|||
const res = await app.request('/api/doc')
|
||||
expect(res.status).toBe(200)
|
||||
})
|
||||
|
||||
it('Should retain defaultHook of the parent app', async () => {
|
||||
const defaultHook = () => {}
|
||||
const app = new OpenAPIHono({
|
||||
defaultHook
|
||||
}).basePath('/api')
|
||||
expect(app.defaultHook).toBeDefined()
|
||||
expect(app.defaultHook).toBe(defaultHook)
|
||||
})
|
||||
})
|
||||
|
||||
describe('With hc', () => {
|
||||
|
|
Loading…
Reference in New Issue