From f14f0c8cf592cddb027ddac97a94076eb8ee229b Mon Sep 17 00:00:00 2001 From: Sor4chi <80559385+sor4chi@users.noreply.github.com> Date: Tue, 21 Nov 2023 16:58:48 +0900 Subject: [PATCH] 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 --- packages/zod-openapi/README.md | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packages/zod-openapi/README.md b/packages/zod-openapi/README.md index 6bbe75da..8d849c3f 100644 --- a/packages/zod-openapi/README.md +++ b/packages/zod-openapi/README.md @@ -284,6 +284,50 @@ const appRoutes = app.openapi(route, (c) => { const client = hc('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`