@hono/zod-openapi 0.4.0 → 0.5.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
@@ -203,6 +203,18 @@ import { prettyJSON } from 'hono/pretty-json'
203
203
  app.use('/doc/*', prettyJSON())
204
204
  ```
205
205
 
206
+ ### Configure middleware for each endpoint
207
+
208
+ You can configure middleware for each endpoint from a route created by `createRoute` as follows.
209
+
210
+ ```ts
211
+ import { prettyJSON } from 'hono/pretty-json'
212
+ import { cache } from 'honoc/cache'
213
+
214
+ app.use(route.getRoutingPath(), prettyJSON(), cache({ cacheName: "my-cache" }))
215
+ app.openapi(route, handler)
216
+ ```
217
+
206
218
  ### RPC Mode
207
219
 
208
220
  Zod OpenAPI Hono supports Hono's RPC mode. You can define types for the Hono Client as follows:
package/dist/index.cjs CHANGED
@@ -141,7 +141,14 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
141
141
  return this;
142
142
  }
143
143
  };
144
- var createRoute = (routeConfig) => routeConfig;
144
+ var createRoute = (routeConfig) => {
145
+ return {
146
+ ...routeConfig,
147
+ getRoutingPath() {
148
+ return routeConfig.path.replaceAll(/\/{(.+?)}/g, "/:$1");
149
+ }
150
+ };
151
+ };
145
152
  (0, import_zod_to_openapi2.extendZodWithOpenApi)(import_zod.z);
146
153
  // Annotate the CommonJS export names for ESM import in node:
147
154
  0 && (module.exports = {
package/dist/index.d.cts CHANGED
@@ -64,8 +64,11 @@ declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath e
64
64
  route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string>(path: SubPath, app: Hono<SubEnv, SubSchema, SubBasePath>): OpenAPIHono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>;
65
65
  route<SubPath extends string>(path: SubPath): Hono<E, RemoveBlankRecord<S>, BasePath>;
66
66
  }
67
+ type RoutingPath<P extends string> = P extends `${infer Head}/{${infer Param}}${infer Tail}` ? `${Head}/:${Param}${RoutingPath<Tail>}` : P;
67
68
  declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"> & {
68
69
  path: P;
69
- }>(routeConfig: R) => R;
70
+ }>(routeConfig: R) => R & {
71
+ getRoutingPath(): RoutingPath<R["path"]>;
72
+ };
70
73
 
71
74
  export { OpenAPIHono, createRoute };
package/dist/index.d.ts CHANGED
@@ -64,8 +64,11 @@ declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath e
64
64
  route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string>(path: SubPath, app: Hono<SubEnv, SubSchema, SubBasePath>): OpenAPIHono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>;
65
65
  route<SubPath extends string>(path: SubPath): Hono<E, RemoveBlankRecord<S>, BasePath>;
66
66
  }
67
+ type RoutingPath<P extends string> = P extends `${infer Head}/{${infer Param}}${infer Tail}` ? `${Head}/:${Param}${RoutingPath<Tail>}` : P;
67
68
  declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"> & {
68
69
  path: P;
69
- }>(routeConfig: R) => R;
70
+ }>(routeConfig: R) => R & {
71
+ getRoutingPath(): RoutingPath<R["path"]>;
72
+ };
70
73
 
71
74
  export { OpenAPIHono, createRoute };
package/dist/index.js CHANGED
@@ -115,7 +115,14 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
115
115
  return this;
116
116
  }
117
117
  };
118
- var createRoute = (routeConfig) => routeConfig;
118
+ var createRoute = (routeConfig) => {
119
+ return {
120
+ ...routeConfig,
121
+ getRoutingPath() {
122
+ return routeConfig.path.replaceAll(/\/{(.+?)}/g, "/:$1");
123
+ }
124
+ };
125
+ };
119
126
  extendZodWithOpenApi(z);
120
127
  export {
121
128
  OpenAPIHono,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/zod-openapi",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "A wrapper class of Hono which supports OpenAPI.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",