@hono/zod-openapi 0.10.0 → 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 +26 -0
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +4 -2
- package/dist/index.mjs +4 -2
- package/package.json +1 -1
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 {
|
|
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 {
|
|
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
|
-
|
|
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) => {
|
|
@@ -153,12 +154,13 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
|
|
|
153
154
|
}
|
|
154
155
|
};
|
|
155
156
|
var createRoute = (routeConfig) => {
|
|
156
|
-
|
|
157
|
+
const route = {
|
|
157
158
|
...routeConfig,
|
|
158
159
|
getRoutingPath() {
|
|
159
160
|
return routeConfig.path.replaceAll(/\/{(.+?)}/g, "/:$1");
|
|
160
161
|
}
|
|
161
162
|
};
|
|
163
|
+
return Object.defineProperty(route, "getRoutingPath", { enumerable: false });
|
|
162
164
|
};
|
|
163
165
|
(0, import_zod_to_openapi2.extendZodWithOpenApi)(import_zod.z);
|
|
164
166
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -56,7 +56,8 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
|
|
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) => {
|
|
@@ -131,12 +132,13 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
|
|
|
131
132
|
}
|
|
132
133
|
};
|
|
133
134
|
var createRoute = (routeConfig) => {
|
|
134
|
-
|
|
135
|
+
const route = {
|
|
135
136
|
...routeConfig,
|
|
136
137
|
getRoutingPath() {
|
|
137
138
|
return routeConfig.path.replaceAll(/\/{(.+?)}/g, "/:$1");
|
|
138
139
|
}
|
|
139
140
|
};
|
|
141
|
+
return Object.defineProperty(route, "getRoutingPath", { enumerable: false });
|
|
140
142
|
};
|
|
141
143
|
extendZodWithOpenApi(z);
|
|
142
144
|
export {
|