docs(zod-openapi): update readme

pull/145/head
Yusuke Wada 2023-08-27 09:30:05 +09:00
parent 5f3ef12c95
commit 7fdc882e7c
1 changed files with 41 additions and 4 deletions

View File

@ -4,10 +4,6 @@
_Note: This is not standalone middleware but is hosted on the monorepo "[github.com/honojs/middleware](https://github.com/honojs/middleware)"._ _Note: This is not standalone middleware but is hosted on the monorepo "[github.com/honojs/middleware](https://github.com/honojs/middleware)"._
## Limitations
- An instance of Zod OpenAPI Hono cannot be used as a "subApp" in conjunction with `rootApp.route('/api', subApp)`.
## Usage ## Usage
### Installation ### Installation
@ -208,6 +204,47 @@ const appRoutes = app.openapi(route, (c) => {
const client = hc<typeof appRoutes>('http://localhost:8787/') const client = hc<typeof appRoutes>('http://localhost:8787/')
``` ```
## Limitations
An instance of Zod OpenAPI Hono cannot be used as a "subApp" in conjunction with `rootApp.route('/api', subApp)`.
Use `app.mount('/api', subApp.fetch)` instead.
```ts
const api = OpenAPIHono()
// ...
// Set the `/api` as a base path in the document.
api.get('/doc', (c) => {
const url = new URL(c.req.url)
url.pathname = '/api'
url.search = ''
return c.json(
// `api.getOpenAPIDocument()` will return a JSON object of the docs.
api.getOpenAPIDocument({
openapi: '3.0.0',
info: {
version: '1.0.0',
title: 'My API',
},
servers: [
{
url: `${url.toString()}`,
},
],
})
)
})
const app = new Hono()
// Mount the Open API app to `/api` in the main app.
app.mount('/api', api.fetch)
export default app
```
## References ## References
- [Hono](https://hono.dev/) - [Hono](https://hono.dev/)