From 5b82c0b79ea01bc85e76e1ef435cc547bca03d70 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Thu, 24 Aug 2023 17:06:00 +0900 Subject: [PATCH 1/3] fix(zod-openapi): bump up Hono --- packages/zod-openapi/package.json | 3 ++- packages/zod-openapi/src/index.ts | 24 +++++++++++++------- packages/zod-openapi/test/index.test.ts | 30 +++++++++++-------------- yarn.lock | 7 +++++- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/packages/zod-openapi/package.json b/packages/zod-openapi/package.json index 0f424b2f..fee2f119 100644 --- a/packages/zod-openapi/package.json +++ b/packages/zod-openapi/package.json @@ -31,7 +31,8 @@ "zod": "3.*" }, "devDependencies": { - "hono": "^3.4.3", + "@hono/zod-validator": "^0.1.8", + "hono": "^3.5.4", "zod": "^3.22.1" }, "dependencies": { diff --git a/packages/zod-openapi/src/index.ts b/packages/zod-openapi/src/index.ts index 3570772a..bfc1de50 100644 --- a/packages/zod-openapi/src/index.ts +++ b/packages/zod-openapi/src/index.ts @@ -11,8 +11,16 @@ import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi' import type { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator' import { zValidator } from '@hono/zod-validator' import { Hono } from 'hono' -import type { Context, Input, Schema, TypedResponse } from 'hono' -import type { Env, Handler, MiddlewareHandler } from 'hono' +import type { + Context, + Env, + Handler, + Input, + MiddlewareHandler, + Schema, + ToSchema, + TypedResponse, +} from 'hono' import type { AnyZodObject, ZodSchema, ZodError } from 'zod' import { z, ZodType } from 'zod' @@ -133,11 +141,11 @@ type ConvertPathType = T extends `${infer _}/{${infer Param}}$ ? `/:${Param}` : T -export class OpenAPIHono extends Hono< - E, - S, - BasePath -> { +export class OpenAPIHono< + E extends Env = Env, + S extends Schema = {}, + BasePath extends string = '/' +> extends Hono { #registry: OpenAPIRegistry constructor() { @@ -153,7 +161,7 @@ export class OpenAPIHono>, hook?: Hook> - ): Hono>, BasePath> => { + ): Hono>, BasePath> => { this.#registry.registerPath(route) const validators: MiddlewareHandler[] = [] diff --git a/packages/zod-openapi/test/index.test.ts b/packages/zod-openapi/test/index.test.ts index b3c0539f..91cecd80 100644 --- a/packages/zod-openapi/test/index.test.ts +++ b/packages/zod-openapi/test/index.test.ts @@ -1,9 +1,7 @@ /* eslint-disable node/no-extraneous-import */ /* eslint-disable @typescript-eslint/no-explicit-any */ -import type { Env } from 'hono' -import type { Hono } from 'hono' +import type { Hono, Env, ToSchema } from 'hono' import { describe, it, expect, expectTypeOf } from 'vitest' -import type { Schema } from 'zod' import { OpenAPIHono, createRoute, z } from '../src' describe('Basic - params', () => { @@ -435,22 +433,20 @@ describe('Types', () => { it('Should return correct types', () => { type H = Hono< Env, - Schema<{ - '/posts': { - $post: { - input: { - json: { - title: string - id: number - } - } - output: { - id: number - message: string - } + ToSchema< + 'post', + '/posts', + { + json: { + title: string + id: number } + }, + { + id: number + message: string } - }>, + >, '/' > expectTypeOf(appRoutes).toMatchTypeOf diff --git a/yarn.lock b/yarn.lock index 99e6b4c7..6ec8b8c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5823,7 +5823,7 @@ hono@^3.0.0, hono@^3.0.3, hono@^3.1.0, hono@^3.1.2, hono@^3.2.6: resolved "https://registry.yarnpkg.com/hono/-/hono-3.2.6.tgz#b4927ed20b2edf165277f3e2b787a4e4948223f6" integrity sha512-jUf9SgkTW/H3Pd9oPwFgf3j05RXUbILWm96WlHll56t2Jkv8tVXyfLeBzYwdTzB7JE/hx+DWMXrVJ06UdfcKng== -hono@^3.1.5, hono@^3.4.3: +hono@^3.1.5: version "3.4.3" resolved "https://registry.yarnpkg.com/hono/-/hono-3.4.3.tgz#ab1db8777fa80341daf389979b7888da0786e3db" integrity sha512-HbVxZh9yC3hV25+mFjUaM65t7g8ia2mXbhAGmVHA0r8+guizTJq1Cg4f2SmB5+JrviG0vaqOnWJ9U3O05aikbA== @@ -5838,6 +5838,11 @@ hono@^3.5.2: resolved "https://registry.yarnpkg.com/hono/-/hono-3.5.2.tgz#83776c4f076c40f59850105af835a6a5609b7d07" integrity sha512-HezADUIepgTpn+LSHNU2vZd4V2wcFDkObycShxhR37eXwQXgjev9FHsxBpDkvPqGQLn3YAPiC3GNVZVUsbcwFg== +hono@^3.5.4: + version "3.5.4" + resolved "https://registry.yarnpkg.com/hono/-/hono-3.5.4.tgz#66057d4c1ee127faafa087168af6d569ab25f5e7" + integrity sha512-GrRBIJhZ+tG+8RtoyPQjvqPGwppERmayyTiPKano4egmpkJf1XiptESUYK5vKHICNaJksAKB9jzy1CmOdQENPA== + hosted-git-info@^2.1.4: version "2.8.9" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" From 23f931a4032431d63662e757face05c73480551c Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Thu, 24 Aug 2023 17:08:20 +0900 Subject: [PATCH 2/3] fix dependencies --- packages/zod-openapi/package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/zod-openapi/package.json b/packages/zod-openapi/package.json index fee2f119..dd3a4ab2 100644 --- a/packages/zod-openapi/package.json +++ b/packages/zod-openapi/package.json @@ -31,15 +31,14 @@ "zod": "3.*" }, "devDependencies": { - "@hono/zod-validator": "^0.1.8", "hono": "^3.5.4", "zod": "^3.22.1" }, "dependencies": { "@asteasolutions/zod-to-openapi": "^5.5.0", - "@hono/zod-validator": "^0.1.7" + "@hono/zod-validator": "^0.1.8" }, "engines": { "node": ">=16.0.0" } -} +} \ No newline at end of file From 2a6ab43d74576c5d806efd73a9ec2c6d50098795 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Thu, 24 Aug 2023 17:09:33 +0900 Subject: [PATCH 3/3] changeset --- .changeset/strange-pumas-tickle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strange-pumas-tickle.md diff --git a/.changeset/strange-pumas-tickle.md b/.changeset/strange-pumas-tickle.md new file mode 100644 index 00000000..17ab2cb8 --- /dev/null +++ b/.changeset/strange-pumas-tickle.md @@ -0,0 +1,5 @@ +--- +'@hono/zod-openapi': patch +--- + +fix: bump up Hono version