Skip to content

Commit

Permalink
fix(zod-openapi): BasePath not included in client types (#429)
Browse files Browse the repository at this point in the history
fixes #428
  • Loading branch information
hmnd authored Mar 22, 2024
1 parent 6bdbf88 commit b1f8a53
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-donuts-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/zod-openapi': patch
---

fix: base path not included in client types
2 changes: 1 addition & 1 deletion packages/zod-openapi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class OpenAPIHono<
: HandlerAllResponse<OutputType<R>>
>,
hook: Hook<I, E, P, OutputType<R>> | undefined = this.defaultHook
): OpenAPIHono<E, S & ToSchema<R['method'], P, I['in'], OutputType<R>>, BasePath> => {
): OpenAPIHono<E, S & ToSchema<R['method'], MergePath<BasePath, P>, I['in'], OutputType<R>>, BasePath> => {
this.openAPIRegistry.registerPath(route)

const validators: MiddlewareHandler[] = []
Expand Down
4 changes: 2 additions & 2 deletions packages/zod-openapi/test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Types', () => {
const appRoutes = app.openapi(route, (c) => {
const data = c.req.valid('json')
assertType<number>(data.id)
return c.jsonT({
return c.json({
id: data.id,
message: 'Success',
})
Expand All @@ -70,7 +70,7 @@ describe('Types', () => {
'/'
>
expectTypeOf(appRoutes).toMatchTypeOf<H>()
})
});
})

describe('Input types', () => {
Expand Down
10 changes: 10 additions & 0 deletions packages/zod-openapi/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,16 @@ describe('basePath()', () => {
expect(app.defaultHook).toBeDefined()
expect(app.defaultHook).toBe(defaultHook)
})

it('Should include base path in typings', () => {
const routes = new OpenAPIHono()
.basePath('/api')
.openapi(route, (c) => c.json({ message: 'Hello' }))

const client = hc<typeof routes>('http://localhost/')

expect(client.api.message.$url().pathname).toBe('/api/message')
})
})

describe('With hc', () => {
Expand Down

0 comments on commit b1f8a53

Please sign in to comment.