Skip to content

Commit

Permalink
docs(zod-openapi): add components registoration and auth configutatio…
Browse files Browse the repository at this point in the history
…n tips (#271)

* docs(zod-openapi): update README

* docs(zod-openapi): add custom components reference of Zod OpenAPI
  • Loading branch information
sor4chi authored Nov 21, 2023
1 parent bae3c0f commit f14f0c8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/zod-openapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,50 @@ const appRoutes = app.openapi(route, (c) => {
const client = hc<typeof appRoutes>('http://localhost:8787/')
```

## Tips

### How to register components

You can register components to the registry as follows:

```ts
app.openAPIRegistry.registerComponent('schemas', {
User: UserSchema,
})
```

About this feature, please refer to [the "Zod to OpenAPI" resource / Defining Custom Components](https://github.com/asteasolutions/zod-to-openapi#defining-custom-components)

### How to setup authorization

You can setup authorization as follows:

eg. Bearer Auth

Register the security scheme:

```ts
app.openAPIRegistry.registerComponent('securitySchema', {
Bearer: {
type: 'http',
scheme: 'bearer',
},
}
```
And setup the security scheme for specific routes:
```ts
const route = createRoute({
// ...
security: [
{
Bearer: [],
},
],
})
```
## Limitations
### Combining with `Hono`
Expand Down

0 comments on commit f14f0c8

Please sign in to comment.