From 9f64138406a2c513462f2a4873b2ef8be36df9d8 Mon Sep 17 00:00:00 2001 From: Jonathan Haines Date: Fri, 27 Jun 2025 11:42:46 +1000 Subject: [PATCH] refactor(zod-openai): enable isolated declarations (#1217) --- .changeset/petite-masks-melt.md | 5 +++++ packages/zod-openapi/package.json | 3 ++- packages/zod-openapi/src/index.ts | 14 +++++++------- packages/zod-openapi/tsconfig.build.json | 4 +--- yarn.lock | 19 +++++++++++++++++++ 5 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 .changeset/petite-masks-melt.md diff --git a/.changeset/petite-masks-melt.md b/.changeset/petite-masks-melt.md new file mode 100644 index 00000000..afa8b24c --- /dev/null +++ b/.changeset/petite-masks-melt.md @@ -0,0 +1,5 @@ +--- +'@hono/zod-openapi': patch +--- + +Add explicit return types diff --git a/packages/zod-openapi/package.json b/packages/zod-openapi/package.json index de6242f8..8f33d5d3 100644 --- a/packages/zod-openapi/package.json +++ b/packages/zod-openapi/package.json @@ -53,7 +53,8 @@ }, "dependencies": { "@asteasolutions/zod-to-openapi": "^7.3.0", - "@hono/zod-validator": "workspace:^" + "@hono/zod-validator": "workspace:^", + "openapi3-ts": "^4.5.0" }, "engines": { "node": ">=16.0.0" diff --git a/packages/zod-openapi/src/index.ts b/packages/zod-openapi/src/index.ts index 957b9b0f..b156405d 100644 --- a/packages/zod-openapi/src/index.ts +++ b/packages/zod-openapi/src/index.ts @@ -36,6 +36,8 @@ import type { } from 'hono/utils/http-status' import type { JSONParsed, JSONValue, RemoveBlankRecord, SimplifyDeepArray } from 'hono/utils/types' import { mergePath } from 'hono/utils/url' +import type { OpenAPIObject } from 'openapi3-ts/oas30' +import type { OpenAPIObject as OpenAPIV31bject } from 'openapi3-ts/oas31' import type { ZodError, ZodSchema } from 'zod' import { ZodType, z } from 'zod' @@ -555,18 +557,14 @@ export class OpenAPIHono< return this } - getOpenAPIDocument = ( - config: OpenAPIObjectConfig - ): ReturnType => { + getOpenAPIDocument = (config: OpenAPIObjectConfig): OpenAPIObject => { const generator = new OpenApiGeneratorV3(this.openAPIRegistry.definitions) const document = generator.generateDocument(config) // @ts-expect-error the _basePath is a private property return this._basePath ? addBasePathToDocument(document, this._basePath) : document } - getOpenAPI31Document = ( - config: OpenAPIObjectConfig - ): ReturnType => { + getOpenAPI31Document = (config: OpenAPIObjectConfig): OpenAPIV31bject => { const generator = new OpenApiGeneratorV31(this.openAPIRegistry.definitions) const document = generator.generateDocument(config) // @ts-expect-error the _basePath is a private property @@ -690,7 +688,9 @@ type RoutingPath

= P extends `${infer Head}/{${infer Param}}${ export const createRoute =

& { path: P }>( routeConfig: R -) => { +): R & { + getRoutingPath(): RoutingPath +} => { const route = { ...routeConfig, getRoutingPath(): RoutingPath { diff --git a/packages/zod-openapi/tsconfig.build.json b/packages/zod-openapi/tsconfig.build.json index 4af91e57..5435fc8f 100644 --- a/packages/zod-openapi/tsconfig.build.json +++ b/packages/zod-openapi/tsconfig.build.json @@ -1,7 +1,5 @@ { "extends": "../../tsconfig.build.json", - "compilerOptions": { - "isolatedDeclarations": false - }, + "compilerOptions": {}, "references": [{ "path": "../zod-validator/tsconfig.build.json" }] } diff --git a/yarn.lock b/yarn.lock index a853e7a8..254237b4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2697,6 +2697,7 @@ __metadata: "@arethetypeswrong/cli": "npm:^0.17.4" "@asteasolutions/zod-to-openapi": "npm:^7.3.0" "@hono/zod-validator": "workspace:^" + openapi3-ts: "npm:^4.5.0" publint: "npm:^0.3.9" tsup: "npm:^8.4.0" typescript: "npm:^5.8.2" @@ -12039,6 +12040,15 @@ __metadata: languageName: node linkType: hard +"openapi3-ts@npm:^4.5.0": + version: 4.5.0 + resolution: "openapi3-ts@npm:4.5.0" + dependencies: + yaml: "npm:^2.8.0" + checksum: 10c0/97de2d24e9ceffb89e1388e137e4a6e17ee57a02dce0c938a5e98b1338ac72b31e8b2ce8dd28945ad43fae8bee2a145892cb548ba5ae60b0930f1b6b79b0747d + languageName: node + linkType: hard + "optionator@npm:^0.9.3": version: 0.9.4 resolution: "optionator@npm:0.9.4" @@ -16604,6 +16614,15 @@ __metadata: languageName: node linkType: hard +"yaml@npm:^2.8.0": + version: 2.8.0 + resolution: "yaml@npm:2.8.0" + bin: + yaml: bin.mjs + checksum: 10c0/f6f7310cf7264a8107e72c1376f4de37389945d2fb4656f8060eca83f01d2d703f9d1b925dd8f39852a57034fafefde6225409ddd9f22aebfda16c6141b71858 + languageName: node + linkType: hard + "yargs-parser@npm:^20.2.2": version: 20.2.9 resolution: "yargs-parser@npm:20.2.9"