fix(zod-openapi): enable `basePath()` (#179)
* fix(zod-openapi): enable `basePath()` * add changesetpull/177/head
parent
9c45dbc41d
commit
047eca5ca9
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@hono/zod-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(zod-openapi): enable `basePath()`
|
|
@ -347,6 +347,10 @@ export class OpenAPIHono<
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
return this as any
|
return this as any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
basePath<SubPath extends string>(path: SubPath): OpenAPIHono<E, S, MergePath<BasePath, SubPath>> {
|
||||||
|
return new OpenAPIHono(super.basePath(path))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type RoutingPath<P extends string> = P extends `${infer Head}/{${infer Param}}${infer Tail}`
|
type RoutingPath<P extends string> = P extends `${infer Head}/{${infer Param}}${infer Tail}`
|
||||||
|
|
|
@ -728,6 +728,39 @@ describe('Multi params', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('basePath()', () => {
|
||||||
|
const route = createRoute({
|
||||||
|
method: 'get',
|
||||||
|
path: '/message',
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'Get message',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const app = new OpenAPIHono().basePath('/api')
|
||||||
|
app.openapi(route, (c) => c.jsonT({ message: 'Hello' }))
|
||||||
|
app.doc('/doc', {
|
||||||
|
openapi: '3.0.0',
|
||||||
|
info: {
|
||||||
|
version: '1.0.0',
|
||||||
|
title: 'My API',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should return 200 response without type errors - /api/message', async () => {
|
||||||
|
const res = await app.request('/api/message')
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
expect(await res.json()).toEqual({ message: 'Hello' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should return 200 response - /api/doc', async () => {
|
||||||
|
const res = await app.request('/api/doc')
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('With hc', () => {
|
describe('With hc', () => {
|
||||||
describe('Multiple routes', () => {
|
describe('Multiple routes', () => {
|
||||||
const app = new OpenAPIHono()
|
const app = new OpenAPIHono()
|
||||||
|
|
Loading…
Reference in New Issue