docs(zod-openapi): add components registoration and auth configutation tips (#271)

* docs(zod-openapi): update README

* docs(zod-openapi): add custom components reference of Zod OpenAPI
pull/266/head
Sor4chi 2023-11-21 16:58:48 +09:00 committed by GitHub
parent bae3c0fd43
commit f14f0c8cf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 0 deletions

View File

@ -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`