Skip to content

Commit

Permalink
feat(zod-openapi): Make it possible to do method chaining even for do…
Browse files Browse the repository at this point in the history
…c methods
  • Loading branch information
Karibash committed Nov 16, 2023
1 parent 4c5b5be commit 904fb48
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-dodos-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/zod-openapi': patch
---

Make it possible to do method chaining even for doc methods
19 changes: 13 additions & 6 deletions packages/zod-openapi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -277,18 +278,24 @@ export class OpenAPIHono<
return document
}

doc = (path: string, config: OpenAPIObjectConfig) => {
this.get(path, (c) => {
doc = <P extends string>(
path: P,
config: OpenAPIObjectConfig
): OpenAPIHono<E, S & ToSchema<'get', P, {}, OpenAPIObject>, 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 = <P extends string>(
path: P,
config: OpenAPIObjectConfig
): OpenAPIHono<E, S & ToSchema<'get', P, {}, OpenAPIObject>, BasePath> => {
return this.get(path, (c) => {
const document = this.getOpenAPI31Document(config)
return c.json(document)
})
}) as any
}

route<
Expand Down

0 comments on commit 904fb48

Please sign in to comment.