From 904fb48d0d8bd90603f725001de0d40ec1859ead Mon Sep 17 00:00:00 2001 From: Karibash Date: Fri, 17 Nov 2023 01:42:19 +0900 Subject: [PATCH] feat(zod-openapi): Make it possible to do method chaining even for doc methods --- .changeset/tame-dodos-grab.md | 5 +++++ packages/zod-openapi/src/index.ts | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 .changeset/tame-dodos-grab.md diff --git a/.changeset/tame-dodos-grab.md b/.changeset/tame-dodos-grab.md new file mode 100644 index 00000000..ccb1b237 --- /dev/null +++ b/.changeset/tame-dodos-grab.md @@ -0,0 +1,5 @@ +--- +'@hono/zod-openapi': patch +--- + +Make it possible to do method chaining even for doc methods diff --git a/packages/zod-openapi/src/index.ts b/packages/zod-openapi/src/index.ts index 08f51a59..56f29161 100644 --- a/packages/zod-openapi/src/index.ts +++ b/packages/zod-openapi/src/index.ts @@ -28,6 +28,7 @@ import type { import type { MergePath, MergeSchemaPath } from 'hono/types' import type { RemoveBlankRecord } from 'hono/utils/types' import { mergePath } from 'hono/utils/url' +import type { OpenAPIObject } from 'openapi3-ts/oas30' import type { AnyZodObject, ZodSchema, ZodError } from 'zod' import { z, ZodType } from 'zod' @@ -277,18 +278,24 @@ export class OpenAPIHono< return document } - doc = (path: string, config: OpenAPIObjectConfig) => { - this.get(path, (c) => { + doc =

( + path: P, + config: OpenAPIObjectConfig + ): OpenAPIHono, BasePath> => { + return this.get(path, (c) => { const document = this.getOpenAPIDocument(config) return c.json(document) - }) + }) as any } - doc31 = (path: string, config: OpenAPIObjectConfig) => { - this.get(path, (c) => { + doc31 =

( + path: P, + config: OpenAPIObjectConfig + ): OpenAPIHono, BasePath> => { + return this.get(path, (c) => { const document = this.getOpenAPI31Document(config) return c.json(document) - }) + }) as any } route<