@hono/zod-openapi
Advanced tools
Comparing version 0.10.1 to 0.11.0
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31'; | ||
import * as openapi3_ts_oas30 from 'openapi3-ts/oas30'; | ||
import { RouteConfig, ZodMediaTypeObject, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi'; | ||
import { ZodMediaTypeObject, OpenAPIRegistry, RouteConfig as RouteConfig$1, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi'; | ||
import { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator'; | ||
import { Env, Context, TypedResponse, Input, Handler, Schema, Hono, ToSchema } from 'hono'; | ||
import { Env, Context, TypedResponse, Input, Handler, Schema, Hono, ToSchema, MiddlewareHandler } from 'hono'; | ||
import { MergePath, MergeSchemaPath } from 'hono/types'; | ||
@@ -11,2 +11,5 @@ import { RemoveBlankRecord } from 'hono/utils/types'; | ||
type RouteConfig = RouteConfig$1 & { | ||
middleware?: MiddlewareHandler | MiddlewareHandler[]; | ||
}; | ||
type RequestTypes = { | ||
@@ -13,0 +16,0 @@ body?: ZodRequestBody; |
@@ -81,3 +81,4 @@ "use strict"; | ||
} | ||
this.on([route.method], route.path.replaceAll(/\/{(.+?)}/g, "/:$1"), ...validators, handler); | ||
const middleware = route.middleware ? Array.isArray(route.middleware) ? route.middleware : [route.middleware] : []; | ||
this.on([route.method], route.path.replaceAll(/\/{(.+?)}/g, "/:$1"), ...middleware, ...validators, handler); | ||
return this; | ||
@@ -84,0 +85,0 @@ }; |
{ | ||
"name": "@hono/zod-openapi", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "A wrapper class of Hono which supports OpenAPI.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -273,2 +273,28 @@ # Zod OpenAPI Hono | ||
Or you can use the `middleware` property in the route definition. | ||
```ts | ||
const route = createRoute({ | ||
method: 'get', | ||
path: '/users/{id}', | ||
request: { | ||
params: ParamsSchema, | ||
}, | ||
middleware: [ | ||
prettyJSON(), | ||
cache({ cacheName: 'my-cache' }) | ||
], | ||
responses: { | ||
200: { | ||
content: { | ||
'application/json': { | ||
schema: UserSchema, | ||
}, | ||
}, | ||
description: 'Retrieve the user', | ||
}, | ||
}, | ||
}) | ||
``` | ||
### RPC Mode | ||
@@ -275,0 +301,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
36678
426
413