hono-openapi 0.3.1 → 0.4.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/LICENSE +21 -21
- package/README.md +252 -252
- package/arktype.cjs +1 -0
- package/arktype.d.cts +1 -0
- package/arktype.d.ts +1 -0
- package/arktype.js +1 -0
- package/effect.cjs +1 -0
- package/effect.d.cts +1 -0
- package/effect.d.ts +1 -0
- package/effect.js +1 -0
- package/index.cjs +1 -0
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +77 -32
- package/src/arktype.d.ts +13 -1
- package/src/effect.d.ts +12 -1
- package/src/helper.d.ts +1 -1
- package/src/index.d.ts +3 -3
- package/src/openapi.d.ts +200 -3
- package/src/route.d.ts +41 -1
- package/src/typebox.d.ts +13 -1
- package/src/types.d.ts +7 -4
- package/src/utils.d.ts +1 -1
- package/src/valibot.d.ts +13 -1
- package/src/zod.d.ts +13 -1
- package/typebox.cjs +1 -0
- package/typebox.d.cts +1 -0
- package/typebox.d.ts +1 -0
- package/typebox.js +1 -0
- package/valibot.cjs +1 -0
- package/valibot.d.cts +1 -0
- package/valibot.d.ts +1 -0
- package/valibot.js +1 -0
- package/zod.cjs +1 -0
- package/zod.d.cts +1 -0
- package/zod.d.ts +1 -0
- package/zod.js +1 -0
- package/arktype.cjs.d.ts +0 -1
- package/arktype.cjs.js +0 -1
- package/arktype.esm.d.ts +0 -1
- package/arktype.esm.js +0 -1
- package/effect.cjs.d.ts +0 -1
- package/effect.cjs.js +0 -1
- package/effect.esm.d.ts +0 -1
- package/effect.esm.js +0 -1
- package/index.cjs.d.ts +0 -1
- package/index.cjs.js +0 -1
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -1
- package/typebox.cjs.d.ts +0 -1
- package/typebox.cjs.js +0 -1
- package/typebox.esm.d.ts +0 -1
- package/typebox.esm.js +0 -1
- package/valibot.cjs.d.ts +0 -1
- package/valibot.cjs.js +0 -1
- package/valibot.esm.d.ts +0 -1
- package/valibot.esm.js +0 -1
- package/zod.cjs.d.ts +0 -1
- package/zod.cjs.js +0 -1
- package/zod.esm.d.ts +0 -1
- package/zod.esm.js +0 -1
- /package/{toOpenAPISchema.cjs.js → toOpenAPISchema.cjs} +0 -0
- /package/{toOpenAPISchema.esm.js → toOpenAPISchema.js} +0 -0
- /package/{utils.cjs.js → utils.cjs} +0 -0
- /package/{utils.esm.js → utils.js} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono-openapi",
|
|
3
3
|
"description": "OpenAPI schema generator for Hono",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"type": "module",
|
|
5
8
|
"license": "MIT",
|
|
6
9
|
"keywords": [
|
|
7
10
|
"hono",
|
|
@@ -27,15 +30,15 @@
|
|
|
27
30
|
"dependencies": {
|
|
28
31
|
"json-schema-walker": "^2.0.0"
|
|
29
32
|
},
|
|
30
|
-
"
|
|
33
|
+
"peerDependencies": {
|
|
31
34
|
"@hono/arktype-validator": "^2.0.0",
|
|
32
35
|
"@hono/effect-validator": "^1.2.0",
|
|
33
|
-
"@hono/typebox-validator": "^0.2.
|
|
36
|
+
"@hono/typebox-validator": "^0.2.0 || ^0.3.0",
|
|
34
37
|
"@hono/valibot-validator": "^0.5.1",
|
|
35
38
|
"@hono/zod-validator": "^0.4.1",
|
|
36
39
|
"@sinclair/typebox": "^0.34.9",
|
|
37
40
|
"@valibot/to-json-schema": "^1.0.0-beta.3",
|
|
38
|
-
"arktype": "2.0.0-rc.25",
|
|
41
|
+
"arktype": "^2.0.0-rc.25",
|
|
39
42
|
"effect": "^3.11.3",
|
|
40
43
|
"hono": "^4.6.13",
|
|
41
44
|
"openapi-types": "^12.1.3",
|
|
@@ -43,74 +46,116 @@
|
|
|
43
46
|
"zod": "^3.23.8",
|
|
44
47
|
"zod-openapi": "^4.0.0"
|
|
45
48
|
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"@hono/arktype-validator": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"@hono/effect-validator": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"@hono/typebox-validator": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"@hono/valibot-validator": {
|
|
60
|
+
"optional": true
|
|
61
|
+
},
|
|
62
|
+
"@hono/zod-validator": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"@sinclair/typebox": {
|
|
66
|
+
"optional": true
|
|
67
|
+
},
|
|
68
|
+
"@valibot/to-json-schema": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"arktype": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"effect": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"hono": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"openapi-types": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"valibot": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"zod": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"zod-openapi": {
|
|
90
|
+
"optional": true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
46
93
|
"devDependencies": {
|
|
47
|
-
"@apidevtools/json-schema-ref-parser": "^11.7.
|
|
94
|
+
"@apidevtools/json-schema-ref-parser": "^11.7.3",
|
|
48
95
|
"@rollup/plugin-terser": "^0.4.4",
|
|
49
96
|
"@types/json-schema": "^7.0.15"
|
|
50
97
|
},
|
|
51
98
|
"exports": {
|
|
52
99
|
".": {
|
|
53
100
|
"import": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
101
|
+
"types": "./index.d.ts",
|
|
102
|
+
"default": "./index.js"
|
|
56
103
|
},
|
|
57
104
|
"require": {
|
|
58
|
-
"
|
|
59
|
-
"
|
|
105
|
+
"types": "./index.d.cts",
|
|
106
|
+
"default": "./index.cjs"
|
|
60
107
|
}
|
|
61
108
|
},
|
|
62
109
|
"./zod": {
|
|
63
110
|
"import": {
|
|
64
|
-
"
|
|
65
|
-
"
|
|
111
|
+
"types": "./zod.d.ts",
|
|
112
|
+
"default": "./zod.js"
|
|
66
113
|
},
|
|
67
114
|
"require": {
|
|
68
|
-
"
|
|
69
|
-
"
|
|
115
|
+
"types": "./zod.d.cts",
|
|
116
|
+
"default": "./zod.cjs"
|
|
70
117
|
}
|
|
71
118
|
},
|
|
72
119
|
"./valibot": {
|
|
73
120
|
"import": {
|
|
74
|
-
"
|
|
75
|
-
"
|
|
121
|
+
"types": "./valibot.d.ts",
|
|
122
|
+
"default": "./valibot.js"
|
|
76
123
|
},
|
|
77
124
|
"require": {
|
|
78
|
-
"
|
|
79
|
-
"
|
|
125
|
+
"types": "./valibot.d.cts",
|
|
126
|
+
"default": "./valibot.cjs"
|
|
80
127
|
}
|
|
81
128
|
},
|
|
82
129
|
"./typebox": {
|
|
83
130
|
"import": {
|
|
84
|
-
"
|
|
85
|
-
"
|
|
131
|
+
"types": "./typebox.d.ts",
|
|
132
|
+
"default": "./typebox.js"
|
|
86
133
|
},
|
|
87
134
|
"require": {
|
|
88
|
-
"
|
|
89
|
-
"
|
|
135
|
+
"types": "./typebox.d.cts",
|
|
136
|
+
"default": "./typebox.cjs"
|
|
90
137
|
}
|
|
91
138
|
},
|
|
92
139
|
"./arktype": {
|
|
93
140
|
"import": {
|
|
94
|
-
"
|
|
95
|
-
"
|
|
141
|
+
"types": "./arktype.d.ts",
|
|
142
|
+
"default": "./arktype.js"
|
|
96
143
|
},
|
|
97
144
|
"require": {
|
|
98
|
-
"
|
|
99
|
-
"
|
|
145
|
+
"types": "./arktype.d.cts",
|
|
146
|
+
"default": "./arktype.cjs"
|
|
100
147
|
}
|
|
101
148
|
},
|
|
102
149
|
"./effect": {
|
|
103
150
|
"import": {
|
|
104
|
-
"
|
|
105
|
-
"
|
|
151
|
+
"types": "./effect.d.ts",
|
|
152
|
+
"default": "./effect.js"
|
|
106
153
|
},
|
|
107
154
|
"require": {
|
|
108
|
-
"
|
|
109
|
-
"
|
|
155
|
+
"types": "./effect.d.cts",
|
|
156
|
+
"default": "./effect.cjs"
|
|
110
157
|
}
|
|
111
158
|
}
|
|
112
159
|
},
|
|
113
|
-
"module": "./index.esm.js"
|
|
114
|
-
"main": "./index.cjs.js",
|
|
115
|
-
"types": "./index.esm.d.ts"
|
|
160
|
+
"module": "./index.esm.js"
|
|
116
161
|
}
|
package/src/arktype.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { type Hook } from "@hono/arktype-validator";
|
|
2
2
|
import type { Type } from "arktype";
|
|
3
3
|
import type { Env, MiddlewareHandler, ValidationTargets } from "hono";
|
|
4
|
-
import type { HasUndefined, ResolverResult } from "./types";
|
|
4
|
+
import type { HasUndefined, ResolverResult } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generate a resolver for an Arktype schema
|
|
7
|
+
* @param schema Arktype schema
|
|
8
|
+
* @returns Resolver result
|
|
9
|
+
*/
|
|
5
10
|
export declare function resolver<T extends Type>(schema: T): ResolverResult;
|
|
11
|
+
/**
|
|
12
|
+
* Create a validator middleware
|
|
13
|
+
* @param target Target for validation
|
|
14
|
+
* @param schema Arktype schema
|
|
15
|
+
* @param hook Hook for validation
|
|
16
|
+
* @returns Middleware handler
|
|
17
|
+
*/
|
|
6
18
|
export declare function validator<T extends Type, Target extends keyof ValidationTargets, E extends Env, P extends string, I = T["inferIn"], O = T["infer"], V extends {
|
|
7
19
|
in: HasUndefined<I> extends true ? {
|
|
8
20
|
[K in Target]?: I;
|
package/src/effect.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import type { Env, Input as HonoInput, MiddlewareHandler, ValidationTargets } from "hono";
|
|
3
|
-
import type { HasUndefined, ResolverResult } from "./types";
|
|
3
|
+
import type { HasUndefined, ResolverResult } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Generate a resolver for an Effect schema
|
|
6
|
+
* @param schema Effect schema
|
|
7
|
+
* @returns Resolver result
|
|
8
|
+
*/
|
|
4
9
|
export declare function resolver<Type, Context>(schema: Schema.Schema<Type, Context, never>): ResolverResult;
|
|
10
|
+
/**
|
|
11
|
+
* Create a validator middleware
|
|
12
|
+
* @param target Target for validation
|
|
13
|
+
* @param schema Effect schema
|
|
14
|
+
* @returns Middleware handler
|
|
15
|
+
*/
|
|
5
16
|
export declare function validator<Type, Context, Target extends keyof ValidationTargets, E extends Env, P extends string, In = Schema.Schema<Type, Context, never>["Encoded"], Out = Schema.Schema<Type, Context, never>["Type"], I extends HonoInput = {
|
|
6
17
|
in: HasUndefined<In> extends true ? {
|
|
7
18
|
[K in Target]?: K extends "json" ? In : HasUndefined<keyof ValidationTargets[K]> extends true ? {
|
package/src/helper.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from "openapi-types";
|
|
2
|
-
import type { OpenAPIRoute } from "./types";
|
|
2
|
+
import type { OpenAPIRoute } from "./types.js";
|
|
3
3
|
export declare const ALLOWED_METHODS: readonly ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
|
|
4
4
|
export declare const toOpenAPIPath: (path: string) => string;
|
|
5
5
|
export declare const capitalize: (word: string) => string;
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { describeRoute } from "./route";
|
|
2
|
-
export { openAPISpecs } from "./openapi";
|
|
3
|
-
export type * from "./types";
|
|
1
|
+
export { describeRoute } from "./route.js";
|
|
2
|
+
export { openAPISpecs, generateSpecs } from "./openapi.js";
|
|
3
|
+
export type * from "./types.js";
|
package/src/openapi.d.ts
CHANGED
|
@@ -1,4 +1,201 @@
|
|
|
1
|
-
import type { Env, Hono, Input, Schema } from "hono";
|
|
1
|
+
import type { Context, Env, Hono, Input, Schema } from "hono";
|
|
2
2
|
import type { BlankEnv, BlankInput, BlankSchema, MiddlewareHandler } from "hono/types";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type { OpenAPIV3 } from "openapi-types";
|
|
4
|
+
import type { OpenAPIRouteHandlerConfig, OpenApiSpecsOptions } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Route handler for OpenAPI specs
|
|
7
|
+
* @param hono Instance of Hono
|
|
8
|
+
* @param options Options for generating OpenAPI specs
|
|
9
|
+
* @returns Middleware handler for OpenAPI specs
|
|
10
|
+
*/
|
|
11
|
+
export declare function openAPISpecs<E extends Env = BlankEnv, P extends string = string, I extends Input = BlankInput, S extends Schema = BlankSchema>(hono: Hono<E, S, P>, options?: OpenApiSpecsOptions): MiddlewareHandler<E, P, I>;
|
|
12
|
+
/**
|
|
13
|
+
* Generate OpenAPI specs for the given Hono instance
|
|
14
|
+
* @param hono Instance of Hono
|
|
15
|
+
* @param options Options for generating OpenAPI specs
|
|
16
|
+
* @param config Configuration for OpenAPI route handler
|
|
17
|
+
* @param Context Route context for hiding routes
|
|
18
|
+
* @returns OpenAPI specs
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateSpecs<E extends Env = BlankEnv, P extends string = string, I extends Input = BlankInput, S extends Schema = BlankSchema>(hono: Hono<E, S, P>, { documentation, excludeStaticFile, exclude, excludeMethods, excludeTags, defaultOptions, }?: OpenApiSpecsOptions, { version, components }?: OpenAPIRouteHandlerConfig, c?: Context<E, P, I>): Promise<{
|
|
21
|
+
tags: OpenAPIV3.TagObject[] | undefined;
|
|
22
|
+
info: {
|
|
23
|
+
title: string;
|
|
24
|
+
description: string;
|
|
25
|
+
termsOfService?: string;
|
|
26
|
+
contact?: OpenAPIV3.ContactObject;
|
|
27
|
+
license?: OpenAPIV3.LicenseObject;
|
|
28
|
+
version: string;
|
|
29
|
+
};
|
|
30
|
+
paths: {
|
|
31
|
+
[x: string]: ({
|
|
32
|
+
$ref?: string;
|
|
33
|
+
summary?: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
servers?: OpenAPIV3.ServerObject[];
|
|
36
|
+
parameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[];
|
|
37
|
+
} & {
|
|
38
|
+
get?: {
|
|
39
|
+
tags?: string[];
|
|
40
|
+
summary?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
externalDocs?: OpenAPIV3.ExternalDocumentationObject;
|
|
43
|
+
operationId?: string;
|
|
44
|
+
parameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[];
|
|
45
|
+
requestBody?: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject;
|
|
46
|
+
responses: OpenAPIV3.ResponsesObject;
|
|
47
|
+
callbacks?: {
|
|
48
|
+
[callback: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.CallbackObject;
|
|
49
|
+
};
|
|
50
|
+
deprecated?: boolean;
|
|
51
|
+
security?: OpenAPIV3.SecurityRequirementObject[];
|
|
52
|
+
servers?: OpenAPIV3.ServerObject[];
|
|
53
|
+
} | undefined;
|
|
54
|
+
put?: {
|
|
55
|
+
tags?: string[];
|
|
56
|
+
summary?: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
externalDocs?: OpenAPIV3.ExternalDocumentationObject;
|
|
59
|
+
operationId?: string;
|
|
60
|
+
parameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[];
|
|
61
|
+
requestBody?: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject;
|
|
62
|
+
responses: OpenAPIV3.ResponsesObject;
|
|
63
|
+
callbacks?: {
|
|
64
|
+
[callback: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.CallbackObject;
|
|
65
|
+
};
|
|
66
|
+
deprecated?: boolean;
|
|
67
|
+
security?: OpenAPIV3.SecurityRequirementObject[];
|
|
68
|
+
servers?: OpenAPIV3.ServerObject[];
|
|
69
|
+
} | undefined;
|
|
70
|
+
post?: {
|
|
71
|
+
tags?: string[];
|
|
72
|
+
summary?: string;
|
|
73
|
+
description?: string;
|
|
74
|
+
externalDocs?: OpenAPIV3.ExternalDocumentationObject;
|
|
75
|
+
operationId?: string;
|
|
76
|
+
parameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[];
|
|
77
|
+
requestBody?: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject;
|
|
78
|
+
responses: OpenAPIV3.ResponsesObject;
|
|
79
|
+
callbacks?: {
|
|
80
|
+
[callback: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.CallbackObject;
|
|
81
|
+
};
|
|
82
|
+
deprecated?: boolean;
|
|
83
|
+
security?: OpenAPIV3.SecurityRequirementObject[];
|
|
84
|
+
servers?: OpenAPIV3.ServerObject[];
|
|
85
|
+
} | undefined;
|
|
86
|
+
delete?: {
|
|
87
|
+
tags?: string[];
|
|
88
|
+
summary?: string;
|
|
89
|
+
description?: string;
|
|
90
|
+
externalDocs?: OpenAPIV3.ExternalDocumentationObject;
|
|
91
|
+
operationId?: string;
|
|
92
|
+
parameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[];
|
|
93
|
+
requestBody?: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject;
|
|
94
|
+
responses: OpenAPIV3.ResponsesObject;
|
|
95
|
+
callbacks?: {
|
|
96
|
+
[callback: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.CallbackObject;
|
|
97
|
+
};
|
|
98
|
+
deprecated?: boolean;
|
|
99
|
+
security?: OpenAPIV3.SecurityRequirementObject[];
|
|
100
|
+
servers?: OpenAPIV3.ServerObject[];
|
|
101
|
+
} | undefined;
|
|
102
|
+
options?: {
|
|
103
|
+
tags?: string[];
|
|
104
|
+
summary?: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
externalDocs?: OpenAPIV3.ExternalDocumentationObject;
|
|
107
|
+
operationId?: string;
|
|
108
|
+
parameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[];
|
|
109
|
+
requestBody?: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject;
|
|
110
|
+
responses: OpenAPIV3.ResponsesObject;
|
|
111
|
+
callbacks?: {
|
|
112
|
+
[callback: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.CallbackObject;
|
|
113
|
+
};
|
|
114
|
+
deprecated?: boolean;
|
|
115
|
+
security?: OpenAPIV3.SecurityRequirementObject[];
|
|
116
|
+
servers?: OpenAPIV3.ServerObject[];
|
|
117
|
+
} | undefined;
|
|
118
|
+
head?: {
|
|
119
|
+
tags?: string[];
|
|
120
|
+
summary?: string;
|
|
121
|
+
description?: string;
|
|
122
|
+
externalDocs?: OpenAPIV3.ExternalDocumentationObject;
|
|
123
|
+
operationId?: string;
|
|
124
|
+
parameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[];
|
|
125
|
+
requestBody?: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject;
|
|
126
|
+
responses: OpenAPIV3.ResponsesObject;
|
|
127
|
+
callbacks?: {
|
|
128
|
+
[callback: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.CallbackObject;
|
|
129
|
+
};
|
|
130
|
+
deprecated?: boolean;
|
|
131
|
+
security?: OpenAPIV3.SecurityRequirementObject[];
|
|
132
|
+
servers?: OpenAPIV3.ServerObject[];
|
|
133
|
+
} | undefined;
|
|
134
|
+
patch?: {
|
|
135
|
+
tags?: string[];
|
|
136
|
+
summary?: string;
|
|
137
|
+
description?: string;
|
|
138
|
+
externalDocs?: OpenAPIV3.ExternalDocumentationObject;
|
|
139
|
+
operationId?: string;
|
|
140
|
+
parameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[];
|
|
141
|
+
requestBody?: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject;
|
|
142
|
+
responses: OpenAPIV3.ResponsesObject;
|
|
143
|
+
callbacks?: {
|
|
144
|
+
[callback: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.CallbackObject;
|
|
145
|
+
};
|
|
146
|
+
deprecated?: boolean;
|
|
147
|
+
security?: OpenAPIV3.SecurityRequirementObject[];
|
|
148
|
+
servers?: OpenAPIV3.ServerObject[];
|
|
149
|
+
} | undefined;
|
|
150
|
+
trace?: {
|
|
151
|
+
tags?: string[];
|
|
152
|
+
summary?: string;
|
|
153
|
+
description?: string;
|
|
154
|
+
externalDocs?: OpenAPIV3.ExternalDocumentationObject;
|
|
155
|
+
operationId?: string;
|
|
156
|
+
parameters?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[];
|
|
157
|
+
requestBody?: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject;
|
|
158
|
+
responses: OpenAPIV3.ResponsesObject;
|
|
159
|
+
callbacks?: {
|
|
160
|
+
[callback: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.CallbackObject;
|
|
161
|
+
};
|
|
162
|
+
deprecated?: boolean;
|
|
163
|
+
security?: OpenAPIV3.SecurityRequirementObject[];
|
|
164
|
+
servers?: OpenAPIV3.ServerObject[];
|
|
165
|
+
} | undefined;
|
|
166
|
+
}) | undefined;
|
|
167
|
+
};
|
|
168
|
+
components: {
|
|
169
|
+
schemas: {
|
|
170
|
+
[x: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject;
|
|
171
|
+
};
|
|
172
|
+
responses?: {
|
|
173
|
+
[key: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.ResponseObject;
|
|
174
|
+
};
|
|
175
|
+
parameters?: {
|
|
176
|
+
[key: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject;
|
|
177
|
+
};
|
|
178
|
+
examples?: {
|
|
179
|
+
[key: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.ExampleObject;
|
|
180
|
+
};
|
|
181
|
+
requestBodies?: {
|
|
182
|
+
[key: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject;
|
|
183
|
+
};
|
|
184
|
+
headers?: {
|
|
185
|
+
[key: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.HeaderObject;
|
|
186
|
+
};
|
|
187
|
+
securitySchemes?: {
|
|
188
|
+
[key: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.SecuritySchemeObject;
|
|
189
|
+
};
|
|
190
|
+
links?: {
|
|
191
|
+
[key: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.LinkObject;
|
|
192
|
+
};
|
|
193
|
+
callbacks?: {
|
|
194
|
+
[key: string]: OpenAPIV3.ReferenceObject | OpenAPIV3.CallbackObject;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
openapi: string;
|
|
198
|
+
servers?: OpenAPIV3.ServerObject[] | undefined;
|
|
199
|
+
security?: OpenAPIV3.SecurityRequirementObject[] | undefined;
|
|
200
|
+
externalDocs?: OpenAPIV3.ExternalDocumentationObject | undefined;
|
|
201
|
+
}>;
|
package/src/route.d.ts
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
1
|
import type { MiddlewareHandler } from "hono/types";
|
|
2
|
-
import type { DescribeRouteOptions } from "./types";
|
|
2
|
+
import type { DescribeRouteOptions, OpenAPIRouteHandlerConfig } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Describe a route with OpenAPI specs.
|
|
5
|
+
* @param specs Options for describing a route
|
|
6
|
+
* @returns Middleware handler
|
|
7
|
+
*/
|
|
3
8
|
export declare function describeRoute(specs: DescribeRouteOptions): MiddlewareHandler;
|
|
9
|
+
/**
|
|
10
|
+
* Generate OpenAPI specs for the given route
|
|
11
|
+
* @param config Route handler configuration
|
|
12
|
+
* @param docs Route description in OpenAPI specs
|
|
13
|
+
* @param defaultOptions Default options for describing a route
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateRouteSpecs(config: OpenAPIRouteHandlerConfig, docs: DescribeRouteOptions, defaultOptions?: DescribeRouteOptions): Promise<{
|
|
16
|
+
docs: {
|
|
17
|
+
responses: {
|
|
18
|
+
[x: string]: import("openapi-types").OpenAPIV3.ReferenceObject | (import("openapi-types").OpenAPIV3.ResponseObject & {
|
|
19
|
+
content?: {
|
|
20
|
+
[key: string]: Omit<import("openapi-types").OpenAPIV3.MediaTypeObject, "schema"> & {
|
|
21
|
+
schema?: import("openapi-types").OpenAPIV3.ReferenceObject | import("openapi-types").OpenAPIV3.SchemaObject | import("./types.js").ResolverResult;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
tags?: string[];
|
|
27
|
+
summary?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
externalDocs?: import("openapi-types").OpenAPIV3.ExternalDocumentationObject;
|
|
30
|
+
operationId?: string;
|
|
31
|
+
parameters?: (import("openapi-types").OpenAPIV3.ReferenceObject | import("openapi-types").OpenAPIV3.ParameterObject)[];
|
|
32
|
+
requestBody?: import("openapi-types").OpenAPIV3.ReferenceObject | import("openapi-types").OpenAPIV3.RequestBodyObject;
|
|
33
|
+
callbacks?: {
|
|
34
|
+
[callback: string]: import("openapi-types").OpenAPIV3.ReferenceObject | import("openapi-types").OpenAPIV3.CallbackObject;
|
|
35
|
+
};
|
|
36
|
+
deprecated?: boolean;
|
|
37
|
+
security?: import("openapi-types").OpenAPIV3.SecurityRequirementObject[];
|
|
38
|
+
servers?: import("openapi-types").OpenAPIV3.ServerObject[];
|
|
39
|
+
hide?: boolean | (<E extends import("hono").Env = import("hono").Env, P extends string = string, I extends import("hono").Input = import("hono/types").BlankInput>(c: import("hono").Context<E, P, I>) => boolean);
|
|
40
|
+
validateResponse?: boolean;
|
|
41
|
+
};
|
|
42
|
+
components: {};
|
|
43
|
+
}>;
|
package/src/typebox.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { type Hook } from "@hono/typebox-validator";
|
|
2
2
|
import type { Static, TSchema } from "@sinclair/typebox";
|
|
3
3
|
import type { Env, MiddlewareHandler, ValidationTargets } from "hono";
|
|
4
|
-
import type { ResolverResult } from "./types";
|
|
4
|
+
import type { ResolverResult } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generate a resolver for a TypeBox schema
|
|
7
|
+
* @param schema TypeBox schema
|
|
8
|
+
* @returns Resolver result
|
|
9
|
+
*/
|
|
5
10
|
export declare function resolver<T extends TSchema>(schema: T): ResolverResult;
|
|
11
|
+
/**
|
|
12
|
+
* Create a validator middleware
|
|
13
|
+
* @param target Target for validation
|
|
14
|
+
* @param schema TypeBox schema
|
|
15
|
+
* @param hook Hook for validation
|
|
16
|
+
* @returns Middleware handler
|
|
17
|
+
*/
|
|
6
18
|
export declare function validator<T extends TSchema, Target extends keyof ValidationTargets, E extends Env, P extends string, V extends {
|
|
7
19
|
in: {
|
|
8
20
|
[K in Target]: Static<T>;
|
package/src/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context, Env, Input } from "hono";
|
|
2
2
|
import type { BlankInput } from "hono/types";
|
|
3
3
|
import type { OpenAPIV3 } from "openapi-types";
|
|
4
|
-
import type { ALLOWED_METHODS } from "./helper";
|
|
4
|
+
import type { ALLOWED_METHODS } from "./helper.js";
|
|
5
5
|
export type HasUndefined<T> = undefined extends T ? true : false;
|
|
6
6
|
export type PromiseOr<T> = T | Promise<T>;
|
|
7
7
|
export type OpenAPIRouteHandlerConfig = {
|
|
@@ -18,20 +18,19 @@ export type ResolverResult = {
|
|
|
18
18
|
validator: (values: unknown) => PromiseOr<void>;
|
|
19
19
|
};
|
|
20
20
|
export type HandlerResponse = {
|
|
21
|
-
resolver: (config: OpenAPIRouteHandlerConfig) => PromiseOr<{
|
|
21
|
+
resolver: (config: OpenAPIRouteHandlerConfig, defaultOptions?: DescribeRouteOptions) => PromiseOr<{
|
|
22
22
|
docs: OpenAPIV3.OperationObject;
|
|
23
23
|
components?: OpenAPIV3.ComponentsObject["schemas"];
|
|
24
24
|
}>;
|
|
25
25
|
metadata?: Record<string, unknown>;
|
|
26
26
|
};
|
|
27
|
-
export type DescribeRouteOptions = Omit<OpenAPIV3.OperationObject, "responses"
|
|
27
|
+
export type DescribeRouteOptions = Omit<OpenAPIV3.OperationObject, "responses"> & {
|
|
28
28
|
/**
|
|
29
29
|
* Pass `true` to hide route from OpenAPI/swagger document
|
|
30
30
|
*/
|
|
31
31
|
hide?: boolean | (<E extends Env = Env, P extends string = string, I extends Input = BlankInput>(c: Context<E, P, I>) => boolean);
|
|
32
32
|
/**
|
|
33
33
|
* Validate response of the route
|
|
34
|
-
* @experimental
|
|
35
34
|
*/
|
|
36
35
|
validateResponse?: boolean;
|
|
37
36
|
/**
|
|
@@ -79,4 +78,8 @@ export type OpenApiSpecsOptions = {
|
|
|
79
78
|
* Exclude tags from OpenAPI
|
|
80
79
|
*/
|
|
81
80
|
excludeTags?: string[];
|
|
81
|
+
/**
|
|
82
|
+
* Default options for `describeRoute` method
|
|
83
|
+
*/
|
|
84
|
+
defaultOptions?: Partial<Record<(typeof ALLOWED_METHODS)[number] | "ALL", DescribeRouteOptions>>;
|
|
82
85
|
};
|
package/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ValidationTargets } from "hono";
|
|
2
2
|
import type { OpenAPIV3 } from "openapi-types";
|
|
3
|
-
import type { ResolverResult } from "./types";
|
|
3
|
+
import type { ResolverResult } from "./types.js";
|
|
4
4
|
export declare const uniqueSymbol: unique symbol;
|
|
5
5
|
export declare function generateValidatorDocs<Target extends keyof ValidationTargets>(target: Target, _result: ReturnType<ResolverResult["builder"]>): Promise<{
|
|
6
6
|
docs: Pick<{
|
package/src/valibot.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { type Hook } from "@hono/valibot-validator";
|
|
2
2
|
import type { Env, Input as HonoInput, MiddlewareHandler, ValidationTargets } from "hono";
|
|
3
3
|
import { type BaseIssue, type BaseSchema, type GenericSchema, type GenericSchemaAsync, type InferInput, type InferOutput } from "valibot";
|
|
4
|
-
import type { HasUndefined, ResolverResult } from "./types";
|
|
4
|
+
import type { HasUndefined, ResolverResult } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generate a resolver for a Valibot schema
|
|
7
|
+
* @param schema Valibot schema
|
|
8
|
+
* @returns Resolver result
|
|
9
|
+
*/
|
|
5
10
|
export declare function resolver<T extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(schema: T): ResolverResult;
|
|
11
|
+
/**
|
|
12
|
+
* Create a validator middleware
|
|
13
|
+
* @param target Target for validation
|
|
14
|
+
* @param schema Valibot schema
|
|
15
|
+
* @param hook Hook for validation
|
|
16
|
+
* @returns Middleware handler
|
|
17
|
+
*/
|
|
6
18
|
export declare function validator<T extends GenericSchema | GenericSchemaAsync, Target extends keyof ValidationTargets, E extends Env, P extends string, In = InferInput<T>, Out = InferOutput<T>, I extends HonoInput = {
|
|
7
19
|
in: HasUndefined<In> extends true ? {
|
|
8
20
|
[K in Target]?: K extends "json" ? In : HasUndefined<keyof ValidationTargets[K]> extends true ? {
|
package/src/zod.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { type Hook } from "@hono/zod-validator";
|
|
2
2
|
import type { Env, Input, MiddlewareHandler, ValidationTargets } from "hono";
|
|
3
3
|
import type { ZodSchema, z } from "zod";
|
|
4
|
-
import type { HasUndefined, ResolverResult } from "./types";
|
|
4
|
+
import type { HasUndefined, ResolverResult } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generate a resolver for a Zod schema
|
|
7
|
+
* @param schema Zod schema
|
|
8
|
+
* @returns Resolver result
|
|
9
|
+
*/
|
|
5
10
|
export declare function resolver<T extends ZodSchema>(schema: T): ResolverResult;
|
|
11
|
+
/**
|
|
12
|
+
* Create a validator middleware
|
|
13
|
+
* @param target Target for validation
|
|
14
|
+
* @param schema Zod schema
|
|
15
|
+
* @param hook Hook for validation
|
|
16
|
+
* @returns Middleware handler
|
|
17
|
+
*/
|
|
6
18
|
export declare function validator<T extends ZodSchema, Target extends keyof ValidationTargets, E extends Env, P extends string, In = z.input<T>, Out = z.output<T>, I extends Input = {
|
|
7
19
|
in: HasUndefined<In> extends true ? {
|
|
8
20
|
[K in Target]?: In extends ValidationTargets[K] ? In : {
|
package/typebox.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@hono/typebox-validator"),r=require("@sinclair/typebox/value"),a=require("./toOpenAPISchema.cjs"),t=require("./utils.cjs");function i(e){return{builder:async r=>({schema:await a.convert(e)}),validator:a=>{r.Value.Parse(e,a)}}}require("json-schema-walker"),exports.resolver=i,exports.validator=function(r,a,o){const s=e.tbValidator(r,a,o);return Object.assign(s,{[t.uniqueSymbol]:{resolver:async e=>t.generateValidatorDocs(r,await i(a).builder(e))}})};
|
package/typebox.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/typebox";
|
package/typebox.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from "./src/typebox.js";
|
package/typebox.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{tbValidator as r}from"@hono/typebox-validator";import{Value as o}from"@sinclair/typebox/value";import{c as a}from"./toOpenAPISchema.js";import{u as t,g as e}from"./utils.js";import"json-schema-walker";function i(r){return{builder:async o=>({schema:await a(r)}),validator:a=>{o.Parse(r,a)}}}function s(o,a,s){const n=r(o,a,s);return Object.assign(n,{[t]:{resolver:async r=>e(o,await i(a).builder(r))}})}export{i as resolver,s as validator};
|
package/valibot.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@hono/valibot-validator"),r=require("@valibot/to-json-schema"),a=require("valibot"),t=require("./toOpenAPISchema.cjs"),o=require("./utils.cjs");function i(e){return{builder:async a=>({schema:await t.convert(r.toJsonSchema(e))}),validator:async r=>{await a.parseAsync(e,r)}}}require("json-schema-walker"),exports.resolver=i,exports.validator=function(r,a,t){const s=e.vValidator(r,a,t);return Object.assign(s,{[o.uniqueSymbol]:{resolver:async e=>o.generateValidatorDocs(r,await i(a).builder(e))}})};
|
package/valibot.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/valibot";
|
package/valibot.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from "./src/valibot.js";
|
package/valibot.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{vValidator as o}from"@hono/valibot-validator";import{toJsonSchema as a}from"@valibot/to-json-schema";import{parseAsync as t}from"valibot";import{c as r}from"./toOpenAPISchema.js";import{u as i,g as s}from"./utils.js";import"json-schema-walker";function m(o){return{builder:async t=>({schema:await r(a(o))}),validator:async a=>{await t(o,a)}}}function n(a,t,r){const n=o(a,t,r);return Object.assign(n,{[i]:{resolver:async o=>s(a,await m(t).builder(o))}})}export{m as resolver,n as validator};
|
package/zod.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@hono/zod-validator"),r=require("zod-openapi"),a=require("./utils.cjs");function t(e){return{builder:a=>{const{version:t,...o}=a??{};return r.createSchema(e,a?{openapi:t,...o}:void 0)},validator:e.parse}}exports.resolver=t,exports.validator=function(r,o,i){const n=e.zValidator(r,o,i);return Object.assign(n,{[a.uniqueSymbol]:{resolver:async e=>a.generateValidatorDocs(r,await t(o).builder(e)),metadata:{schemaType:"input"}}})};
|
package/zod.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/zod";
|
package/zod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from "./src/zod.js";
|
package/zod.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{zValidator as o}from"@hono/zod-validator";import{createSchema as r}from"zod-openapi";import{u as t,g as a}from"./utils.js";function i(o){return{builder:t=>{const{version:a,...i}=t??{};return r(o,t?{openapi:a,...i}:void 0)},validator:o.parse}}function e(r,e,n){const s=o(r,e,n);return Object.assign(s,{[t]:{resolver:async o=>a(r,await i(e).builder(o)),metadata:{schemaType:"input"}}})}export{i as resolver,e as validator};
|
package/arktype.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src\\arktype";
|
package/arktype.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("@hono/arktype-validator"),r=require("./toOpenAPISchema.cjs.js"),a=require("./utils.cjs.js");function t(e){return{builder:async a=>({schema:await r.convert(e.toJsonSchema())}),validator:r=>{e(r)}}}require("json-schema-walker"),exports.resolver=t,exports.validator=function(r,o,s){const i=e.arktypeValidator(r,o,s);return Object.assign(i,{[a.uniqueSymbol]:{resolver:async e=>a.generateValidatorDocs(r,await t(o).builder(e))}})};
|