diff --git a/.changeset/sweet-insects-attack.md b/.changeset/sweet-insects-attack.md new file mode 100644 index 00000000..767550f2 --- /dev/null +++ b/.changeset/sweet-insects-attack.md @@ -0,0 +1,5 @@ +--- +'@hono/zod-openapi': minor +--- + +feat(zod-openapi): make `app.openAPIRegistry` public diff --git a/packages/zod-openapi/README.md b/packages/zod-openapi/README.md index 902f3560..0b8d0fdd 100644 --- a/packages/zod-openapi/README.md +++ b/packages/zod-openapi/README.md @@ -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: diff --git a/packages/zod-openapi/src/index.ts b/packages/zod-openapi/src/index.ts index e51a721a..9143dbf1 100644 --- a/packages/zod-openapi/src/index.ts +++ b/packages/zod-openapi/src/index.ts @@ -150,11 +150,11 @@ export class OpenAPIHono< S extends Schema = {}, BasePath extends string = '/' > extends Hono { - #registry: OpenAPIRegistry + openAPIRegistry: OpenAPIRegistry constructor() { super() - this.#registry = new OpenAPIRegistry() + this.openAPIRegistry = new OpenAPIRegistry() } openapi = < @@ -171,7 +171,7 @@ export class OpenAPIHono< handler: Handler>>, hook?: Hook> ): Hono>, 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 }