docs(zod-openapi): update readme
parent
5f3ef12c95
commit
7fdc882e7c
|
@ -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/)
|
||||||
|
|
Loading…
Reference in New Issue