@hono/zod-openapi 0.5.1 → 0.6.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/dist/index.d.cts +10 -4
- package/dist/index.d.ts +10 -4
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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 { RouteConfig, OpenAPIRegistry, 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,
|
|
5
|
+
import { Env, Input, Handler, Schema, Hono, ToSchema, Context, TypedResponse } from 'hono';
|
|
6
6
|
import { MergeSchemaPath, MergePath } from 'hono/dist/types/types';
|
|
7
7
|
import { RemoveBlankRecord } from 'hono/utils/types';
|
|
8
8
|
import { AnyZodObject, z, ZodSchema, ZodError, ZodType } from 'zod';
|
|
@@ -42,6 +42,10 @@ type InputTypeForm<R extends RouteConfig> = R['request'] extends RequestTypes ?
|
|
|
42
42
|
form: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
|
|
43
43
|
};
|
|
44
44
|
} : {} : {} : {} : {};
|
|
45
|
+
type InputTypeParam<R extends RouteConfig> = InputTypeBase<R, 'params', 'param'>;
|
|
46
|
+
type InputTypeQuery<R extends RouteConfig> = InputTypeBase<R, 'query', 'query'>;
|
|
47
|
+
type InputTypeHeader<R extends RouteConfig> = InputTypeBase<R, 'headers', 'header'>;
|
|
48
|
+
type InputTypeCookie<R extends RouteConfig> = InputTypeBase<R, 'cookies', 'cookie'>;
|
|
45
49
|
type OutputType<R extends RouteConfig> = R['responses'] extends Record<infer _, infer C> ? C extends ResponseConfig ? C['content'] extends ZodContentObject ? IsJson<keyof C['content']> extends never ? {} : C['content'][keyof C['content']]['schema'] extends ZodSchema ? z.infer<C['content'][keyof C['content']]['schema']> : {} : {} : {} : {};
|
|
46
50
|
type Hook<T, E extends Env, P extends string, O> = (result: {
|
|
47
51
|
success: true;
|
|
@@ -53,10 +57,12 @@ type Hook<T, E extends Env, P extends string, O> = (result: {
|
|
|
53
57
|
type ConvertPathType<T extends string> = T extends `${infer _}/{${infer Param}}${infer _}` ? `/:${Param}` : T;
|
|
54
58
|
type HandlerResponse<O> = TypedResponse<O> | Promise<TypedResponse<O>>;
|
|
55
59
|
type HonoInit = ConstructorParameters<typeof Hono>[0];
|
|
60
|
+
type RouteHandler<R extends RouteConfig, E extends Env = Env, I extends Input = InputTypeParam<R> & InputTypeQuery<R> & InputTypeHeader<R> & InputTypeCookie<R> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R['path']>> = Handler<E, P, I, HandlerResponse<OutputType<R>>>;
|
|
61
|
+
type RouteHook<R extends RouteConfig, E extends Env = Env, I extends Input = InputTypeParam<R> & InputTypeQuery<R> & InputTypeHeader<R> & InputTypeCookie<R> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R['path']>> = Hook<I, E, P, OutputType<R>>;
|
|
56
62
|
declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> extends Hono<E, S, BasePath> {
|
|
57
63
|
openAPIRegistry: OpenAPIRegistry;
|
|
58
64
|
constructor(init?: HonoInit);
|
|
59
|
-
openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>(route: R, handler:
|
|
65
|
+
openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>(route: R, handler: RouteHandler<R, E, I, P>, hook?: RouteHook<R, E, I, P> | undefined) => OpenAPIHono<E, ToSchema<R["method"], P, I["in"], OutputType<R>>, BasePath>;
|
|
60
66
|
getOpenAPIDocument: (config: OpenAPIObjectConfig) => openapi3_ts_oas30.OpenAPIObject;
|
|
61
67
|
getOpenAPI31Document: (config: OpenAPIObjectConfig) => openapi3_ts_oas31.OpenAPIObject;
|
|
62
68
|
doc: (path: string, config: OpenAPIObjectConfig) => void;
|
|
@@ -71,4 +77,4 @@ declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"
|
|
|
71
77
|
getRoutingPath(): RoutingPath<R["path"]>;
|
|
72
78
|
};
|
|
73
79
|
|
|
74
|
-
export { OpenAPIHono, createRoute };
|
|
80
|
+
export { OpenAPIHono, RouteHandler, RouteHook, createRoute };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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 { RouteConfig, OpenAPIRegistry, 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,
|
|
5
|
+
import { Env, Input, Handler, Schema, Hono, ToSchema, Context, TypedResponse } from 'hono';
|
|
6
6
|
import { MergeSchemaPath, MergePath } from 'hono/dist/types/types';
|
|
7
7
|
import { RemoveBlankRecord } from 'hono/utils/types';
|
|
8
8
|
import { AnyZodObject, z, ZodSchema, ZodError, ZodType } from 'zod';
|
|
@@ -42,6 +42,10 @@ type InputTypeForm<R extends RouteConfig> = R['request'] extends RequestTypes ?
|
|
|
42
42
|
form: z.output<R['request']['body']['content'][keyof R['request']['body']['content']]['schema']>;
|
|
43
43
|
};
|
|
44
44
|
} : {} : {} : {} : {};
|
|
45
|
+
type InputTypeParam<R extends RouteConfig> = InputTypeBase<R, 'params', 'param'>;
|
|
46
|
+
type InputTypeQuery<R extends RouteConfig> = InputTypeBase<R, 'query', 'query'>;
|
|
47
|
+
type InputTypeHeader<R extends RouteConfig> = InputTypeBase<R, 'headers', 'header'>;
|
|
48
|
+
type InputTypeCookie<R extends RouteConfig> = InputTypeBase<R, 'cookies', 'cookie'>;
|
|
45
49
|
type OutputType<R extends RouteConfig> = R['responses'] extends Record<infer _, infer C> ? C extends ResponseConfig ? C['content'] extends ZodContentObject ? IsJson<keyof C['content']> extends never ? {} : C['content'][keyof C['content']]['schema'] extends ZodSchema ? z.infer<C['content'][keyof C['content']]['schema']> : {} : {} : {} : {};
|
|
46
50
|
type Hook<T, E extends Env, P extends string, O> = (result: {
|
|
47
51
|
success: true;
|
|
@@ -53,10 +57,12 @@ type Hook<T, E extends Env, P extends string, O> = (result: {
|
|
|
53
57
|
type ConvertPathType<T extends string> = T extends `${infer _}/{${infer Param}}${infer _}` ? `/:${Param}` : T;
|
|
54
58
|
type HandlerResponse<O> = TypedResponse<O> | Promise<TypedResponse<O>>;
|
|
55
59
|
type HonoInit = ConstructorParameters<typeof Hono>[0];
|
|
60
|
+
type RouteHandler<R extends RouteConfig, E extends Env = Env, I extends Input = InputTypeParam<R> & InputTypeQuery<R> & InputTypeHeader<R> & InputTypeCookie<R> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R['path']>> = Handler<E, P, I, HandlerResponse<OutputType<R>>>;
|
|
61
|
+
type RouteHook<R extends RouteConfig, E extends Env = Env, I extends Input = InputTypeParam<R> & InputTypeQuery<R> & InputTypeHeader<R> & InputTypeCookie<R> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R['path']>> = Hook<I, E, P, OutputType<R>>;
|
|
56
62
|
declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> extends Hono<E, S, BasePath> {
|
|
57
63
|
openAPIRegistry: OpenAPIRegistry;
|
|
58
64
|
constructor(init?: HonoInit);
|
|
59
|
-
openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>(route: R, handler:
|
|
65
|
+
openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>(route: R, handler: RouteHandler<R, E, I, P>, hook?: RouteHook<R, E, I, P> | undefined) => OpenAPIHono<E, ToSchema<R["method"], P, I["in"], OutputType<R>>, BasePath>;
|
|
60
66
|
getOpenAPIDocument: (config: OpenAPIObjectConfig) => openapi3_ts_oas30.OpenAPIObject;
|
|
61
67
|
getOpenAPI31Document: (config: OpenAPIObjectConfig) => openapi3_ts_oas31.OpenAPIObject;
|
|
62
68
|
doc: (path: string, config: OpenAPIObjectConfig) => void;
|
|
@@ -71,4 +77,4 @@ declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"
|
|
|
71
77
|
getRoutingPath(): RoutingPath<R["path"]>;
|
|
72
78
|
};
|
|
73
79
|
|
|
74
|
-
export { OpenAPIHono, createRoute };
|
|
80
|
+
export { OpenAPIHono, RouteHandler, RouteHook, createRoute };
|