@hono/zod-openapi 0.10.1 → 0.11.1
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 +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +8 -1
- package/dist/index.mjs +8 -1
- 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;
|
|
@@ -53,7 +56,7 @@ type Hook<T, E extends Env, P extends string, O> = (result: {
|
|
|
53
56
|
} | {
|
|
54
57
|
success: false;
|
|
55
58
|
error: ZodError;
|
|
56
|
-
}, c: Context<E, P>) => TypedResponse<O> | Promise<TypedResponse<T>> | Response | Promise<Response> | void
|
|
59
|
+
}, c: Context<E, P>) => TypedResponse<O> | Promise<TypedResponse<T>> | Response | Promise<Response> | void | Promise<void>;
|
|
57
60
|
type ConvertPathType<T extends string> = T extends `${infer Start}/{${infer Param}}${infer Rest}` ? `${Start}/:${Param}${ConvertPathType<Rest>}` : T;
|
|
58
61
|
type HandlerTypedResponse<O> = TypedResponse<O> | Promise<TypedResponse<O>>;
|
|
59
62
|
type HandlerAllResponse<O> = Response | Promise<Response> | TypedResponse<O> | Promise<TypedResponse<O>>;
|
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;
|
|
@@ -53,7 +56,7 @@ type Hook<T, E extends Env, P extends string, O> = (result: {
|
|
|
53
56
|
} | {
|
|
54
57
|
success: false;
|
|
55
58
|
error: ZodError;
|
|
56
|
-
}, c: Context<E, P>) => TypedResponse<O> | Promise<TypedResponse<T>> | Response | Promise<Response> | void
|
|
59
|
+
}, c: Context<E, P>) => TypedResponse<O> | Promise<TypedResponse<T>> | Response | Promise<Response> | void | Promise<void>;
|
|
57
60
|
type ConvertPathType<T extends string> = T extends `${infer Start}/{${infer Param}}${infer Rest}` ? `${Start}/:${Param}${ConvertPathType<Rest>}` : T;
|
|
58
61
|
type HandlerTypedResponse<O> = TypedResponse<O> | Promise<TypedResponse<O>>;
|
|
59
62
|
type HandlerAllResponse<O> = Response | Promise<Response> | TypedResponse<O> | Promise<TypedResponse<O>>;
|
package/dist/index.js
CHANGED
|
@@ -78,7 +78,14 @@ 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(
|
|
83
|
+
[route.method],
|
|
84
|
+
route.path.replaceAll(/\/{(.+?)}/g, "/:$1"),
|
|
85
|
+
...middleware,
|
|
86
|
+
...validators,
|
|
87
|
+
handler
|
|
88
|
+
);
|
|
82
89
|
return this;
|
|
83
90
|
};
|
|
84
91
|
getOpenAPIDocument = (config) => {
|
package/dist/index.mjs
CHANGED
|
@@ -56,7 +56,14 @@ 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(
|
|
61
|
+
[route.method],
|
|
62
|
+
route.path.replaceAll(/\/{(.+?)}/g, "/:$1"),
|
|
63
|
+
...middleware,
|
|
64
|
+
...validators,
|
|
65
|
+
handler
|
|
66
|
+
);
|
|
60
67
|
return this;
|
|
61
68
|
};
|
|
62
69
|
getOpenAPIDocument = (config) => {
|