diff --git a/.changeset/kind-donuts-boil.md b/.changeset/kind-donuts-boil.md new file mode 100644 index 00000000..fdd02e35 --- /dev/null +++ b/.changeset/kind-donuts-boil.md @@ -0,0 +1,5 @@ +--- +'@hono/zod-openapi': patch +--- + +fix: base path not included in client types diff --git a/packages/zod-openapi/src/index.ts b/packages/zod-openapi/src/index.ts index 71166b9b..1e4cc3f2 100644 --- a/packages/zod-openapi/src/index.ts +++ b/packages/zod-openapi/src/index.ts @@ -250,7 +250,7 @@ export class OpenAPIHono< : HandlerAllResponse> >, hook: Hook> | undefined = this.defaultHook - ): OpenAPIHono>, BasePath> => { + ): OpenAPIHono, I['in'], OutputType>, BasePath> => { this.openAPIRegistry.registerPath(route) const validators: MiddlewareHandler[] = [] diff --git a/packages/zod-openapi/test/index.test-d.ts b/packages/zod-openapi/test/index.test-d.ts index ed8c20e8..03051e3a 100644 --- a/packages/zod-openapi/test/index.test-d.ts +++ b/packages/zod-openapi/test/index.test-d.ts @@ -44,7 +44,7 @@ describe('Types', () => { const appRoutes = app.openapi(route, (c) => { const data = c.req.valid('json') assertType(data.id) - return c.jsonT({ + return c.json({ id: data.id, message: 'Success', }) @@ -70,7 +70,7 @@ describe('Types', () => { '/' > expectTypeOf(appRoutes).toMatchTypeOf() - }) + }); }) describe('Input types', () => { diff --git a/packages/zod-openapi/test/index.test.ts b/packages/zod-openapi/test/index.test.ts index 8ce78fa0..8a86d897 100644 --- a/packages/zod-openapi/test/index.test.ts +++ b/packages/zod-openapi/test/index.test.ts @@ -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('http://localhost/') + + expect(client.api.message.$url().pathname).toBe('/api/message') + }) }) describe('With hc', () => {