feat(zod-openapi): make `app.openAPIRegistry` public (#150)
* feat(zod-openapi): make `app.openAPIRegistry` public * changesetpull/149/head
parent
1bfd648df8
commit
1006cbca6b
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@hono/zod-openapi': minor
|
||||
---
|
||||
|
||||
feat(zod-openapi): make `app.openAPIRegistry` public
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue