@hono/zod-openapi 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -270,6 +270,32 @@ app.use(route.getRoutingPath(), prettyJSON(), cache({ cacheName: 'my-cache' }))
270
270
  app.openapi(route, handler)
271
271
  ```
272
272
 
273
+ Or you can use the `middleware` property in the route definition.
274
+
275
+ ```ts
276
+ const route = createRoute({
277
+ method: 'get',
278
+ path: '/users/{id}',
279
+ request: {
280
+ params: ParamsSchema,
281
+ },
282
+ middleware: [
283
+ prettyJSON(),
284
+ cache({ cacheName: 'my-cache' })
285
+ ],
286
+ responses: {
287
+ 200: {
288
+ content: {
289
+ 'application/json': {
290
+ schema: UserSchema,
291
+ },
292
+ },
293
+ description: 'Retrieve the user',
294
+ },
295
+ },
296
+ })
297
+ ```
298
+
273
299
  ### RPC Mode
274
300
 
275
301
  Zod OpenAPI Hono supports Hono's RPC mode. You can define types for the Hono Client as follows:
package/dist/index.d.mts CHANGED
@@ -1,13 +1,16 @@
1
1
  import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
2
  import * as openapi3_ts_oas30 from 'openapi3-ts/oas30';
3
- import { RouteConfig, ZodMediaTypeObject, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
3
+ import { ZodMediaTypeObject, OpenAPIRegistry, RouteConfig as RouteConfig$1, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
4
4
  import { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator';
5
- import { Env, Context, TypedResponse, Input, Handler, Schema, Hono, ToSchema } from 'hono';
5
+ import { Env, Context, TypedResponse, Input, Handler, Schema, Hono, ToSchema, MiddlewareHandler } from 'hono';
6
6
  import { MergePath, MergeSchemaPath } from 'hono/types';
7
7
  import { RemoveBlankRecord } from 'hono/utils/types';
8
8
  import { ZodError, AnyZodObject, z, ZodSchema, ZodType } from 'zod';
9
9
  export { z } from 'zod';
10
10
 
11
+ type RouteConfig = RouteConfig$1 & {
12
+ middleware?: MiddlewareHandler | MiddlewareHandler[];
13
+ };
11
14
  type RequestTypes = {
12
15
  body?: ZodRequestBody;
13
16
  params?: AnyZodObject;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,16 @@
1
1
  import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
2
  import * as openapi3_ts_oas30 from 'openapi3-ts/oas30';
3
- import { RouteConfig, ZodMediaTypeObject, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
3
+ import { ZodMediaTypeObject, OpenAPIRegistry, RouteConfig as RouteConfig$1, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
4
4
  import { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator';
5
- import { Env, Context, TypedResponse, Input, Handler, Schema, Hono, ToSchema } from 'hono';
5
+ import { Env, Context, TypedResponse, Input, Handler, Schema, Hono, ToSchema, MiddlewareHandler } from 'hono';
6
6
  import { MergePath, MergeSchemaPath } from 'hono/types';
7
7
  import { RemoveBlankRecord } from 'hono/utils/types';
8
8
  import { ZodError, AnyZodObject, z, ZodSchema, ZodType } from 'zod';
9
9
  export { z } from 'zod';
10
10
 
11
+ type RouteConfig = RouteConfig$1 & {
12
+ middleware?: MiddlewareHandler | MiddlewareHandler[];
13
+ };
11
14
  type RequestTypes = {
12
15
  body?: ZodRequestBody;
13
16
  params?: AnyZodObject;
package/dist/index.js CHANGED
@@ -78,7 +78,8 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
78
78
  }
79
79
  }
80
80
  }
81
- this.on([route.method], route.path.replaceAll(/\/{(.+?)}/g, "/:$1"), ...validators, handler);
81
+ const middleware = route.middleware ? Array.isArray(route.middleware) ? route.middleware : [route.middleware] : [];
82
+ this.on([route.method], route.path.replaceAll(/\/{(.+?)}/g, "/:$1"), ...middleware, ...validators, handler);
82
83
  return this;
83
84
  };
84
85
  getOpenAPIDocument = (config) => {
package/dist/index.mjs CHANGED
@@ -56,7 +56,8 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
56
56
  }
57
57
  }
58
58
  }
59
- this.on([route.method], route.path.replaceAll(/\/{(.+?)}/g, "/:$1"), ...validators, handler);
59
+ const middleware = route.middleware ? Array.isArray(route.middleware) ? route.middleware : [route.middleware] : [];
60
+ this.on([route.method], route.path.replaceAll(/\/{(.+?)}/g, "/:$1"), ...middleware, ...validators, handler);
60
61
  return this;
61
62
  };
62
63
  getOpenAPIDocument = (config) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/zod-openapi",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "A wrapper class of Hono which supports OpenAPI.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",