@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 +12 -0
- package/dist/index.cjs +8 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +8 -1
- package/package.json +1 -1
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) =>
|
|
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) =>
|
|
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,
|