Skip to content

Commit

Permalink
docs(zod-openapi): update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe committed Aug 27, 2023
1 parent 5f3ef12 commit 7fdc882
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions packages/zod-openapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)"._

## Limitations

- An instance of Zod OpenAPI Hono cannot be used as a "subApp" in conjunction with `rootApp.route('/api', subApp)`.

## Usage

### Installation
Expand Down Expand Up @@ -208,6 +204,47 @@ const appRoutes = app.openapi(route, (c) => {
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

- [Hono](https://hono.dev/)
Expand Down

0 comments on commit 7fdc882

Please sign in to comment.