feat(zod-openapi): make `app.openAPIRegistry` public (#150)

* feat(zod-openapi): make `app.openAPIRegistry` public

* changeset
pull/149/head
Yusuke Wada 2023-09-05 18:55:09 +09:00 committed by GitHub
parent 1bfd648df8
commit 1006cbca6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View File

@ -0,0 +1,5 @@
---
'@hono/zod-openapi': minor
---
feat(zod-openapi): make `app.openAPIRegistry` public

View File

@ -174,6 +174,14 @@ app.openapi(
)
```
### The Registry
You can access the [`OpenAPIRegistry`](https://github.com/asteasolutions/zod-to-openapi#the-registry) object via `app.openAPIRegistry`:
```ts
const registry = app.openAPIRegistry
```
### Middleware
Zod OpenAPI Hono is an extension of Hono, so you can use Hono's middleware in the same way:

View File

@ -150,11 +150,11 @@ export class OpenAPIHono<
S extends Schema = {},
BasePath extends string = '/'
> extends Hono<E, S, BasePath> {
#registry: OpenAPIRegistry
openAPIRegistry: OpenAPIRegistry
constructor() {
super()
this.#registry = new OpenAPIRegistry()
this.openAPIRegistry = new OpenAPIRegistry()
}
openapi = <
@ -171,7 +171,7 @@ export class OpenAPIHono<
handler: Handler<E, P, I, HandlerResponse<OutputType<R>>>,
hook?: Hook<I, E, P, OutputType<R>>
): Hono<E, ToSchema<R['method'], P, I['in'], OutputType<R>>, BasePath> => {
this.#registry.registerPath(route)
this.openAPIRegistry.registerPath(route)
const validators: MiddlewareHandler[] = []
@ -224,7 +224,7 @@ export class OpenAPIHono<
}
getOpenAPIDocument = (config: OpenAPIObjectConfig) => {
const generator = new OpenApiGeneratorV3(this.#registry.definitions)
const generator = new OpenApiGeneratorV3(this.openAPIRegistry.definitions)
const document = generator.generateDocument(config)
return document
}