hono-openapi 0.2.0 → 0.3.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 -240
- package/arktype.cjs.d.ts +1 -1
- package/arktype.cjs.js +1 -1
- package/arktype.esm.d.ts +1 -1
- package/arktype.esm.js +1 -1
- package/effect.cjs.d.ts +1 -0
- package/effect.cjs.js +1 -0
- package/effect.esm.d.ts +1 -0
- package/effect.esm.js +1 -0
- package/index.cjs.d.ts +1 -1
- package/index.cjs.js +1 -1
- package/index.cjs2.js +1 -0
- package/index.esm.d.ts +1 -1
- package/index.esm.js +1 -1
- package/index.esm2.js +1 -0
- package/package.json +20 -5
- package/src/effect.d.ts +22 -0
- package/src/toOpenAPISchema/const.d.ts +1 -0
- package/src/toOpenAPISchema/index.d.ts +5 -0
- package/src/toOpenAPISchema/types.d.ts +18 -0
- package/typebox.cjs.d.ts +1 -1
- package/typebox.cjs.js +1 -1
- package/typebox.esm.d.ts +1 -1
- package/typebox.esm.js +1 -1
- package/utils.cjs.js +1 -1
- package/utils.esm.js +1 -1
- package/valibot.cjs.d.ts +1 -1
- package/valibot.cjs.js +1 -1
- package/valibot.esm.d.ts +1 -1
- package/valibot.esm.js +1 -1
- package/zod.cjs.d.ts +1 -1
- package/zod.esm.d.ts +1 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Rhinobase
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Rhinobase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,240 +1,252 @@
|
|
|
1
|
-
# 📜 Hono OpenAPI
|
|
2
|
-
|
|
3
|
-
[](https://npmjs.org/package/hono-openapi "View this project on NPM")
|
|
4
|
-
[](https://www.npmjs.com/package/hono-openapi)
|
|
5
|
-
[](LICENSE)
|
|
6
|
-
|
|
7
|
-
This can automatically generate the OpenAPI specification for the Hono API using your validation schema, which can be used to generate client libraries, documentation, and more.
|
|
8
|
-
|
|
9
|
-
Supported Validation Libraries:
|
|
10
|
-
|
|
11
|
-
- [x] [Zod](https://zod.dev/)
|
|
12
|
-
- [x] [Valibot](https://valibot.dev/)
|
|
13
|
-
- [x] [ArkType](https://arktype.io/)
|
|
14
|
-
- [x] [TypeBox](https://github.com/sinclairzx81/typebox)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
1
|
+
# 📜 Hono OpenAPI
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.org/package/hono-openapi "View this project on NPM")
|
|
4
|
+
[](https://www.npmjs.com/package/hono-openapi)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
This can automatically generate the OpenAPI specification for the Hono API using your validation schema, which can be used to generate client libraries, documentation, and more.
|
|
8
|
+
|
|
9
|
+
Supported Validation Libraries:
|
|
10
|
+
|
|
11
|
+
- [x] [Zod](https://zod.dev/)
|
|
12
|
+
- [x] [Valibot](https://valibot.dev/)
|
|
13
|
+
- [x] [ArkType](https://arktype.io/)
|
|
14
|
+
- [x] [TypeBox](https://github.com/sinclairzx81/typebox)
|
|
15
|
+
- [x] [Effect](https://effect.website/docs/schema/introduction/)
|
|
16
|
+
|
|
17
|
+
> [!Note]
|
|
18
|
+
> This package is still in development and your feedback is highly appreciated. If you have any suggestions or issues, please let us know by creating an issue on GitHub.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Installation
|
|
23
|
+
|
|
24
|
+
You can install the package using favorite package manager.
|
|
25
|
+
|
|
26
|
+
#### For Zod
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add hono-openapi @hono/zod-validator zod zod-openapi
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### For Valibot
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm add hono-openapi @hono/valibot-validator valibot @valibot/to-json-schema
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### For ArkType
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pnpm add hono-openapi @hono/arktype-validator arktype
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### For TypeBox
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pnpm add hono-openapi @hono/typebox-validator @sinclair/typebox"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### For Effect
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm add hono-openapi @hono/effect-validator effect
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
> [!IMPORTANT]
|
|
57
|
+
>
|
|
58
|
+
> Requires `effect@^3.10.0`.
|
|
59
|
+
> Also, use the `Schema` class from the `effect` package, as `@effect/schema` is not supported.
|
|
60
|
+
|
|
61
|
+
### Basic Usage
|
|
62
|
+
|
|
63
|
+
#### Setting up your application
|
|
64
|
+
|
|
65
|
+
First, define your schemas, here is an example using Zod:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import z from "zod";
|
|
69
|
+
|
|
70
|
+
// For extending the Zod schema with OpenAPI properties
|
|
71
|
+
import "zod-openapi/extend";
|
|
72
|
+
|
|
73
|
+
const querySchema = z
|
|
74
|
+
.object({
|
|
75
|
+
name: z.string().optional().openapi({ example: "Steven" }),
|
|
76
|
+
})
|
|
77
|
+
.openapi({ ref: "Query" });
|
|
78
|
+
|
|
79
|
+
const responseSchema = z.string().openapi({ example: "Hello Steven!" });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Extending the Zod schema with OpenAPI properties is optional, but it will help you generate the OpenAPI specification. You can learn more about it here - [https://github.com/samchungy/zod-openapi](https://github.com/samchungy/zod-openapi).
|
|
83
|
+
|
|
84
|
+
> [!Tip]
|
|
85
|
+
> The `querySchema` schema will be registered as "#/components/schemas/Query" refs in the OpenAPI document. If you want to register the schema as referenced components, use .openapi() method.
|
|
86
|
+
|
|
87
|
+
Next, create your route -
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { Hono } from "hono";
|
|
91
|
+
import { describeRoute } from "hono-openapi";
|
|
92
|
+
import { resolver, validator as zValidator } from "hono-openapi/zod";
|
|
93
|
+
|
|
94
|
+
const app = new Hono();
|
|
95
|
+
|
|
96
|
+
app.get(
|
|
97
|
+
"/",
|
|
98
|
+
describeRoute({
|
|
99
|
+
description: "Say hello to the user",
|
|
100
|
+
responses: {
|
|
101
|
+
200: {
|
|
102
|
+
description: "Successful greeting response",
|
|
103
|
+
content: {
|
|
104
|
+
"text/plain": {
|
|
105
|
+
schema: resolver(responseSchema),
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
zValidator("query", querySchema),
|
|
112
|
+
(c) => {
|
|
113
|
+
const query = c.req.valid("query");
|
|
114
|
+
return c.text(`Hello ${query?.name ?? "Hono"}!`);
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
You might be wondering why are we importing `validator` from `hono-openapi/zod` instead of `@hono/zod-validator` and as `zValidator`? This is because `hono-openapi` provides a wrapper around the `@hono/zod-validator` to make it easier to use. The idea is if you are already using `@hono/zod-validator` to validate your schemas, you can easily switch to `hono-openapi` without changing much of your code.
|
|
120
|
+
|
|
121
|
+
Finally, generate the OpenAPI specification -
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
app.get(
|
|
125
|
+
"/openapi",
|
|
126
|
+
openAPISpecs(app, {
|
|
127
|
+
documentation: {
|
|
128
|
+
info: {
|
|
129
|
+
title: "Hono",
|
|
130
|
+
version: "1.0.0",
|
|
131
|
+
description: "API for greeting users",
|
|
132
|
+
},
|
|
133
|
+
servers: [
|
|
134
|
+
{
|
|
135
|
+
url: "http://localhost:3000",
|
|
136
|
+
description: "Local server",
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Now, you can access the OpenAPI specification by visiting `http://localhost:3000/openapi`, and you can use this specification to generate client libraries, documentation, and more. Some tools that I used to generate documentation are -
|
|
145
|
+
|
|
146
|
+
- [Swagger UI](https://github.com/honojs/middleware/tree/main/packages/swagger-ui)
|
|
147
|
+
- [Scalar](https://github.com/scalar/scalar/tree/main/packages/hono-api-reference)
|
|
148
|
+
|
|
149
|
+
##### Scalar Example
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
app.get(
|
|
153
|
+
"/docs",
|
|
154
|
+
apiReference({
|
|
155
|
+
theme: "saturn",
|
|
156
|
+
spec: {
|
|
157
|
+
url: "/openapi",
|
|
158
|
+
},
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
And that's it! You have successfully generated the OpenAPI specification for your Hono API.
|
|
164
|
+
|
|
165
|
+
### Advanced Usage
|
|
166
|
+
|
|
167
|
+
#### Adding Security Definitions
|
|
168
|
+
|
|
169
|
+
You can add security definitions to your OpenAPI specification by using the `security` property in the `openAPISpecs` function.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
app.get(
|
|
173
|
+
"/openapi",
|
|
174
|
+
openAPISpecs(appRouter, {
|
|
175
|
+
documentation: {
|
|
176
|
+
info: {
|
|
177
|
+
title: "Rhinobase Cloud",
|
|
178
|
+
version: "1.0.0",
|
|
179
|
+
description: "API Documentation",
|
|
180
|
+
},
|
|
181
|
+
components: {
|
|
182
|
+
securitySchemes: {
|
|
183
|
+
bearerAuth: {
|
|
184
|
+
type: "http",
|
|
185
|
+
scheme: "bearer",
|
|
186
|
+
bearerFormat: "JWT",
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
security: [
|
|
191
|
+
{
|
|
192
|
+
bearerAuth: [],
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
servers: [
|
|
196
|
+
{
|
|
197
|
+
url: "http://localhost:3004",
|
|
198
|
+
description: "Local server",
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
#### Conditionaly Hiding Routes
|
|
207
|
+
|
|
208
|
+
You can conditionally hide routes from the OpenAPI specification by using the `hide` property in the `describeRoute` function.
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
app.get(
|
|
212
|
+
"/",
|
|
213
|
+
describeRoute({
|
|
214
|
+
// ...
|
|
215
|
+
hide: process.env.NODE_ENV === "production",
|
|
216
|
+
}),
|
|
217
|
+
(c) => {
|
|
218
|
+
return c.text("Private Route");
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### Validating Responses
|
|
224
|
+
|
|
225
|
+
> [!Warning]
|
|
226
|
+
> Experimental
|
|
227
|
+
|
|
228
|
+
You can validate the responses using the `validateResponse` property in the `describeRoute` function. This will validate the response against the schema and return an error if the response is invalid.
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
app.get(
|
|
232
|
+
"/",
|
|
233
|
+
describeRoute({
|
|
234
|
+
// ...
|
|
235
|
+
validateResponse: true,
|
|
236
|
+
}),
|
|
237
|
+
(c) => {
|
|
238
|
+
return c.json({ message: "This response will be validated" });
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Contributing
|
|
244
|
+
|
|
245
|
+
We would love to have more contributors involved!
|
|
246
|
+
|
|
247
|
+
To get started, please read our [Contributing Guide](https://github.com/rhinobase/hono-openapi/blob/main/CONTRIBUTING.md).
|
|
248
|
+
|
|
249
|
+
## Credits
|
|
250
|
+
|
|
251
|
+
- The idea for this project was inspired by [ElysiaJS](https://elysiajs.com/) and their amazing work on generating [OpenAPI](https://elysiajs.com/recipe/openapi.html) specifications.
|
|
252
|
+
- This project would not have been possible without the work of [Sam Chung](https://github.com/samchungy) and his [Zod OpenAPI](https://github.com/samchungy/zod-openapi) package.
|
package/arktype.cjs.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src
|
|
1
|
+
export * from "./src/arktype";
|
package/arktype.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@hono/arktype-validator"),r=require("
|
|
1
|
+
"use strict";var e=require("@hono/arktype-validator"),r=require("./index.cjs2.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,s,i){const o=e.arktypeValidator(r,s,i);return Object.assign(o,{[a.uniqueSymbol]:{resolver:async e=>a.generateValidatorDocs(r,await t(s).builder(e))}})};
|
package/arktype.esm.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src
|
|
1
|
+
export * from "./src/arktype";
|
package/arktype.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{arktypeValidator as
|
|
1
|
+
import{arktypeValidator as r}from"@hono/arktype-validator";import{c as a}from"./index.esm2.js";import{u as o,g as s}from"./utils.esm.js";import"json-schema-walker";function t(r){return{builder:async o=>({schema:await a(r.toJsonSchema())}),validator:a=>{r(a)}}}function e(a,e,i){const n=r(a,e,i);return Object.assign(n,{[o]:{resolver:async r=>s(a,await t(e).builder(r))}})}export{t as resolver,e as validator};
|
package/effect.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/effect";
|
package/effect.cjs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@hono/effect-validator"),r=require("effect"),a=require("./index.cjs2.js"),t=require("./utils.cjs.js");function i(e){return{builder:async t=>({schema:await a.convert(r.JSONSchema.make(e))}),validator:async a=>{await r.Schema.decodeUnknownPromise(e)(a)}}}require("json-schema-walker"),exports.resolver=i,exports.validator=function(r,a){const s=e.effectValidator(r,a);return Object.assign(s,{[t.uniqueSymbol]:{resolver:async e=>t.generateValidatorDocs(r,await i(a).builder(e))}})};
|
package/effect.esm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/effect";
|
package/effect.esm.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{effectValidator as e}from"@hono/effect-validator";import{JSONSchema as o,Schema as r}from"effect";import{c as a}from"./index.esm2.js";import{u as t,g as s}from"./utils.esm.js";import"json-schema-walker";function i(e){return{builder:async r=>({schema:await a(o.make(e))}),validator:async o=>{await r.decodeUnknownPromise(e)(o)}}}function n(o,r){const a=e(o,r);return Object.assign(a,{[t]:{resolver:async e=>s(o,await i(r).builder(e))}})}export{i as resolver,n as validator};
|
package/index.cjs.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src
|
|
1
|
+
export * from "./src/index";
|
package/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("hono/http-exception"),t=require("./utils.cjs.js");const n=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],s=e=>e.charAt(0).toUpperCase()+e.slice(1),o=(e,t)=>{let n=e;if("/"===t)return`${n}Index`;for(const e of t.split("/"))123===e.charCodeAt(0)?n+=`By${s(e.slice(1,-1))}`:n+=s(e);return n};function c({path:e,method:t,data:n,schema:s}){e=(e=>e.split("/").map((e=>{let t=e;return t.startsWith(":")&&(t=t.slice(1,t.length),t.endsWith("?")&&(t=t.slice(0,-1)),t=`{${t}}`),t})).join("/"))(e);const c=t.toLowerCase();s[e]={...s[e]?s[e]:{},[c]:{responses:{},...s[e]?.[c]??{},operationId:o(c,e),...n}}}function i(e,{excludeStaticFile:t=!0,exclude:n=[]}){const s={};for(const[o,c]of Object.entries(e))if(!(n.some((e=>"string"==typeof e?o===e:e.test(o)))||o.includes("*")||t&&o.includes("."))){for(const e of Object.keys(c)){const t=c[e];o.includes("{")
|
|
1
|
+
"use strict";var e=require("hono/http-exception"),t=require("./utils.cjs.js");const n=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],s=e=>e.charAt(0).toUpperCase()+e.slice(1),o=(e,t)=>{let n=e;if("/"===t)return`${n}Index`;for(const e of t.split("/"))123===e.charCodeAt(0)?n+=`By${s(e.slice(1,-1))}`:n+=s(e);return n};function c({path:e,method:t,data:n,schema:s}){e=(e=>e.split("/").map((e=>{let t=e;return t.startsWith(":")&&(t=t.slice(1,t.length),t.endsWith("?")&&(t=t.slice(0,-1)),t=`{${t}}`),t})).join("/"))(e);const c=t.toLowerCase();s[e]={...s[e]?s[e]:{},[c]:{responses:{},...s[e]?.[c]??{},operationId:o(c,e),...n}}}function i(e,{excludeStaticFile:t=!0,exclude:n=[]}){const s={};for(const[o,c]of Object.entries(e))if(!(n.some((e=>"string"==typeof e?o===e:e.test(o)))||o.includes("*")||t&&o.includes("."))){for(const e of Object.keys(c)){const t=c[e];if(o.includes("{")){t.parameters||(t.parameters=[]);const e=o.split("/").filter((e=>e.startsWith("{")&&!t.parameters.find((t=>"path"===t.in&&t.name===e.slice(1,e.length-1)))));for(const n of e){const e=n.slice(1,n.length-1),s=t.parameters.findIndex((t=>"param"===t.in&&t.name===e));-1!==s?t.parameters[s].in="path":t.parameters.push(n)}}t.responses||(t.responses={200:{}})}s[o]=c}return s}exports.describeRoute=function(n){return Object.assign((async(t,s)=>{if(await s(),n.validateResponse&&n.responses){const s=t.res.status,o=t.res.headers.get("content-type");if(s&&o){const c=n.responses[s];if(c&&"content"in c&&c.content){const n=o.split(";")[0],s=c.content[n];if(s?.schema&&"validator"in s.schema)try{let e;if("application/json"===n?e=await t.res.json():"text/plain"===n&&(e=await t.res.text()),!e)throw new Error("No data to validate!");await s.schema.validator(e)}catch(t){throw new e.HTTPException(400,{message:"Response validation failed!"})}}}}}),{[t.uniqueSymbol]:{resolver:async e=>{const t={...n};let s={};if(t.responses)for(const n of Object.keys(t.responses)){const o=t.responses[n];if(!o||"content"in o)for(const t of Object.keys(o.content??{})){const n=o.content?.[t];if(n&&(n.schema&&"builder"in n.schema)){const t=await n.schema.builder(e);n.schema=t.schema,t.components&&(s={...s,...t.components})}}}return{docs:t,components:s}}}})},exports.openAPISpecs=function(e,{documentation:s={},excludeStaticFile:o=!0,exclude:a=[],excludeMethods:r=["OPTIONS"],excludeTags:l=[]}={documentation:{},excludeStaticFile:!0,exclude:[],excludeMethods:["OPTIONS"],excludeTags:[]}){const p={version:"3.1.0",components:{}},d={};let u=null;return async m=>{if(u)return m.json(u);for(const s of e.routes){if(!(t.uniqueSymbol in s.handler))continue;if(r.includes(s.method))continue;if(!1===n.includes(s.method)&&"ALL"!==s.method)continue;const{resolver:e,metadata:o={}}=s.handler[t.uniqueSymbol],{docs:i,components:a}=await e({...p,...o});if(p.components={...p.components,...a??{}},"ALL"===s.method)for(const e of n)c({path:s.path,data:i,method:e,schema:d});else c({method:s.method,path:s.path,data:i,schema:d})}for(const e in d)for(const t in d[e]){const n=d[e][t]?.hide;n&&("boolean"==typeof n?n:n(m))&&delete d[e][t]}return u={openapi:p.version,...{...s,tags:s.tags?.filter((e=>!l?.includes(e?.name))),info:{title:"Hono Documentation",description:"Development documentation",version:"0.0.0",...s.info},paths:{...i(d,{excludeStaticFile:o,exclude:Array.isArray(a)?a:[a]}),...s.paths},components:{...s.components,schemas:{...p.components,...s.components?.schemas}}}},m.json(u)}};
|
package/index.cjs2.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("json-schema-walker");const t=["$ref","definitions","title","multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","enum","type","not","allOf","oneOf","anyOf","items","properties","additionalProperties","description","format","default","nullable","discriminator","readOnly","writeOnly","example","externalDocs","deprecated","xml"];let n=class extends Error{constructor(e){super(e),this.name="InvalidTypeError",this.message=e}};const i="x-",r=async(t,n)=>{if("object"!=typeof t)return t;if(t.type){const i=new e.Walker;return await i.loadSchema({definitions:n.definitions||[],...t,$schema:n.$schema},{dereference:!0,cloneSchema:!0,dereferenceOptions:{dereference:{circular:"ignore"}}}),await i.walk(o,i.vocabularies.DRAFT_07),"definitions"in i.rootSchema&&(i.rootSchema.definitions=void 0),i.rootSchema}if(Array.isArray(t)){const e=t;if(e.includes("null")){const t=e.filter((e=>"null"!==e));return{type:1===t.length?t[0]:t,nullable:!0}}}return t};function o(e){let r=e;return r?(r=function(e){return"object"!=typeof e||(e.$schema=void 0,e.$id=void 0,"id"in e&&(e.id=void 0)),e}(r),r=function(e){if("object"!=typeof e)return e;if(void 0===e.type)return e;if(function(e){if("object"==typeof e&&!Array.isArray(e)){if(e&&"$ref"in e&&e.$ref)return;if(e&&"properties"in e&&e.properties)return}const t=Array.isArray(e)?e:[e];for(const e of t)if(e&&!a.has(e))throw new n(`Type "${e}" is not a valid type`)}(e.type),Array.isArray(e.type)){e.type.includes("null")&&(e.nullable=!0);const t=e.type.filter((e=>"null"!==e));0===t.length?e.type=void 0:1===t.length?e.type=t[0]:(e.type=void 0,e.anyOf=t.map((e=>({type:e}))))}else"null"===e.type&&(e.type=void 0,e.nullable=!0);return e}(r),r=function(e){Object.hasOwnProperty.call(e,"const")&&(e.enum=[e.const],e.const=void 0);return e}(r),r=function(e){const t=e.dependencies;if("object"!=typeof t)return e;e.dependencies=void 0,Array.isArray(e.allOf)||(e.allOf=[]);for(const n in t){const i={oneOf:[{not:{required:[n]}},{required:[n,t[n]].flat()}]};e.allOf.push(i)}return e}(r),r=function(e){for(const t of["oneOf","anyOf"]){const n=e[t];if(!n)continue;if(!Array.isArray(n))return e;if(!n.some((e=>"null"===e.type)))return e;const i=n.filter((e=>"null"!==e.type));for(const e of i)e.nullable=!0;e[t]=i}return e}(r),r=function(e){if("object"!=typeof e)return e;"if"in e&&e.if&&e.then&&(e.oneOf=[{allOf:[e.if,e.then].filter(Boolean)},{allOf:[{not:e.if},e.else].filter(Boolean)}],e.if=void 0,e.then=void 0,e.else=void 0);return e}(r),r=function(e){"number"==typeof e.exclusiveMaximum&&(e.maximum=e.exclusiveMaximum,e.exclusiveMaximum=!0);"number"==typeof e.exclusiveMinimum&&(e.minimum=e.exclusiveMinimum,e.exclusiveMinimum=!0);return e}(r),r=function(e){e.examples&&Array.isArray(e.examples)&&(e.example=e.examples[0],e.examples=void 0);return e}(r),"object"==typeof r.patternProperties&&(r=function(e){return e["x-patternProperties"]=e.patternProperties,e.patternProperties=void 0,e.additionalProperties??=!0,e}(r)),"array"===r.type&&void 0===r.items&&(r.items={}),r=function(e){const n=Object.keys(e);for(const r of n)if(!r.startsWith(i)&&!t.includes(r)){e[`${i}${r}`]=e[r],e[r]=void 0}return e}(r),r):r}const a=new Set(["null","boolean","object","array","number","string","integer"]);exports.convert=async(t,n)=>{const i=new e.Walker;await i.loadSchema(t,n),await i.walk(o,i.vocabularies.DRAFT_07);const a=i.rootSchema;if(a?.definitions)for(const e in a.definitions){const n=a.definitions[e];a.definitions[e]=await r(n,t)}return a};
|
package/index.esm.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src
|
|
1
|
+
export * from "./src/index";
|
package/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HTTPException as e}from"hono/http-exception";import{u as t}from"./utils.esm.js";function n(n){return Object.assign((async(t,s)=>{if(await s(),n.validateResponse&&n.responses){const s=t.res.status,o=t.res.headers.get("content-type");if(s&&o){const c=n.responses[s];if(c&&"content"in c&&c.content){const n=c.content[
|
|
1
|
+
import{HTTPException as e}from"hono/http-exception";import{u as t}from"./utils.esm.js";function n(n){return Object.assign((async(t,s)=>{if(await s(),n.validateResponse&&n.responses){const s=t.res.status,o=t.res.headers.get("content-type");if(s&&o){const c=n.responses[s];if(c&&"content"in c&&c.content){const n=o.split(";")[0],s=c.content[n];if(s?.schema&&"validator"in s.schema)try{let e;if("application/json"===n?e=await t.res.json():"text/plain"===n&&(e=await t.res.text()),!e)throw new Error("No data to validate!");await s.schema.validator(e)}catch(t){throw new e(400,{message:"Response validation failed!"})}}}}}),{[t]:{resolver:async e=>{const t={...n};let s={};if(t.responses)for(const n of Object.keys(t.responses)){const o=t.responses[n];if(!o||"content"in o)for(const t of Object.keys(o.content??{})){const n=o.content?.[t];if(n&&(n.schema&&"builder"in n.schema)){const t=await n.schema.builder(e);n.schema=t.schema,t.components&&(s={...s,...t.components})}}}return{docs:t,components:s}}}})}const s=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],o=e=>e.charAt(0).toUpperCase()+e.slice(1),c=(e,t)=>{let n=e;if("/"===t)return`${n}Index`;for(const e of t.split("/"))123===e.charCodeAt(0)?n+=`By${o(e.slice(1,-1))}`:n+=o(e);return n};function a({path:e,method:t,data:n,schema:s}){e=(e=>e.split("/").map((e=>{let t=e;return t.startsWith(":")&&(t=t.slice(1,t.length),t.endsWith("?")&&(t=t.slice(0,-1)),t=`{${t}}`),t})).join("/"))(e);const o=t.toLowerCase();s[e]={...s[e]?s[e]:{},[o]:{responses:{},...s[e]?.[o]??{},operationId:c(o,e),...n}}}function i(e,{excludeStaticFile:t=!0,exclude:n=[]}){const s={};for(const[o,c]of Object.entries(e))if(!(n.some((e=>"string"==typeof e?o===e:e.test(o)))||o.includes("*")||t&&o.includes("."))){for(const e of Object.keys(c)){const t=c[e];if(o.includes("{")){t.parameters||(t.parameters=[]);const e=o.split("/").filter((e=>e.startsWith("{")&&!t.parameters.find((t=>"path"===t.in&&t.name===e.slice(1,e.length-1)))));for(const n of e){const e=n.slice(1,n.length-1),s=t.parameters.findIndex((t=>"param"===t.in&&t.name===e));-1!==s?t.parameters[s].in="path":t.parameters.push(n)}}t.responses||(t.responses={200:{}})}s[o]=c}return s}function r(e,{documentation:n={},excludeStaticFile:o=!0,exclude:c=[],excludeMethods:r=["OPTIONS"],excludeTags:l=[]}={documentation:{},excludeStaticFile:!0,exclude:[],excludeMethods:["OPTIONS"],excludeTags:[]}){const p={version:"3.1.0",components:{}},d={};let m=null;return async h=>{if(m)return h.json(m);for(const n of e.routes){if(!(t in n.handler))continue;if(r.includes(n.method))continue;if(!1===s.includes(n.method)&&"ALL"!==n.method)continue;const{resolver:e,metadata:o={}}=n.handler[t],{docs:c,components:i}=await e({...p,...o});if(p.components={...p.components,...i??{}},"ALL"===n.method)for(const e of s)a({path:n.path,data:c,method:e,schema:d});else a({method:n.method,path:n.path,data:c,schema:d})}for(const e in d)for(const t in d[e]){const n=d[e][t]?.hide;n&&("boolean"==typeof n?n:n(h))&&delete d[e][t]}return m={openapi:p.version,...{...n,tags:n.tags?.filter((e=>!l?.includes(e?.name))),info:{title:"Hono Documentation",description:"Development documentation",version:"0.0.0",...n.info},paths:{...i(d,{excludeStaticFile:o,exclude:Array.isArray(c)?c:[c]}),...n.paths},components:{...n.components,schemas:{...p.components,...n.components?.schemas}}}},h.json(m)}}export{n as describeRoute,r as openAPISpecs};
|
package/index.esm2.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Walker as e}from"json-schema-walker";const t=["$ref","definitions","title","multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","enum","type","not","allOf","oneOf","anyOf","items","properties","additionalProperties","description","format","default","nullable","discriminator","readOnly","writeOnly","example","externalDocs","deprecated","xml"];let n=class extends Error{constructor(e){super(e),this.name="InvalidTypeError",this.message=e}};const i="x-",r=async(t,n)=>{if("object"!=typeof t)return t;if(t.type){const i=new e;return await i.loadSchema({definitions:n.definitions||[],...t,$schema:n.$schema},{dereference:!0,cloneSchema:!0,dereferenceOptions:{dereference:{circular:"ignore"}}}),await i.walk(a,i.vocabularies.DRAFT_07),"definitions"in i.rootSchema&&(i.rootSchema.definitions=void 0),i.rootSchema}if(Array.isArray(t)){const e=t;if(e.includes("null")){const t=e.filter((e=>"null"!==e));return{type:1===t.length?t[0]:t,nullable:!0}}}return t},o=async(t,n)=>{const i=new e;await i.loadSchema(t,n),await i.walk(a,i.vocabularies.DRAFT_07);const o=i.rootSchema;if(o?.definitions)for(const e in o.definitions){const n=o.definitions[e];o.definitions[e]=await r(n,t)}return o};function a(e){let r=e;return r?(r=function(e){return"object"!=typeof e||(e.$schema=void 0,e.$id=void 0,"id"in e&&(e.id=void 0)),e}(r),r=function(e){if("object"!=typeof e)return e;if(void 0===e.type)return e;if(function(e){if("object"==typeof e&&!Array.isArray(e)){if(e&&"$ref"in e&&e.$ref)return;if(e&&"properties"in e&&e.properties)return}const t=Array.isArray(e)?e:[e];for(const e of t)if(e&&!s.has(e))throw new n(`Type "${e}" is not a valid type`)}(e.type),Array.isArray(e.type)){e.type.includes("null")&&(e.nullable=!0);const t=e.type.filter((e=>"null"!==e));0===t.length?e.type=void 0:1===t.length?e.type=t[0]:(e.type=void 0,e.anyOf=t.map((e=>({type:e}))))}else"null"===e.type&&(e.type=void 0,e.nullable=!0);return e}(r),r=function(e){Object.hasOwnProperty.call(e,"const")&&(e.enum=[e.const],e.const=void 0);return e}(r),r=function(e){const t=e.dependencies;if("object"!=typeof t)return e;e.dependencies=void 0,Array.isArray(e.allOf)||(e.allOf=[]);for(const n in t){const i={oneOf:[{not:{required:[n]}},{required:[n,t[n]].flat()}]};e.allOf.push(i)}return e}(r),r=function(e){for(const t of["oneOf","anyOf"]){const n=e[t];if(!n)continue;if(!Array.isArray(n))return e;if(!n.some((e=>"null"===e.type)))return e;const i=n.filter((e=>"null"!==e.type));for(const e of i)e.nullable=!0;e[t]=i}return e}(r),r=function(e){if("object"!=typeof e)return e;"if"in e&&e.if&&e.then&&(e.oneOf=[{allOf:[e.if,e.then].filter(Boolean)},{allOf:[{not:e.if},e.else].filter(Boolean)}],e.if=void 0,e.then=void 0,e.else=void 0);return e}(r),r=function(e){"number"==typeof e.exclusiveMaximum&&(e.maximum=e.exclusiveMaximum,e.exclusiveMaximum=!0);"number"==typeof e.exclusiveMinimum&&(e.minimum=e.exclusiveMinimum,e.exclusiveMinimum=!0);return e}(r),r=function(e){e.examples&&Array.isArray(e.examples)&&(e.example=e.examples[0],e.examples=void 0);return e}(r),"object"==typeof r.patternProperties&&(r=function(e){return e["x-patternProperties"]=e.patternProperties,e.patternProperties=void 0,e.additionalProperties??=!0,e}(r)),"array"===r.type&&void 0===r.items&&(r.items={}),r=function(e){const n=Object.keys(e);for(const r of n)if(!r.startsWith(i)&&!t.includes(r)){e[`${i}${r}`]=e[r],e[r]=void 0}return e}(r),r):r}const s=new Set(["null","boolean","object","array","number","string","integer"]);export{o as c};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono-openapi",
|
|
3
3
|
"description": "OpenAPI schema generator for Hono",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"hono",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"zod",
|
|
10
10
|
"valibot",
|
|
11
11
|
"typebox",
|
|
12
|
-
"arktype"
|
|
12
|
+
"arktype",
|
|
13
|
+
"effect"
|
|
13
14
|
],
|
|
14
15
|
"homepage": "https://github.com/rhinobase/hono-openapi",
|
|
15
16
|
"publishConfig": {
|
|
@@ -24,24 +25,28 @@
|
|
|
24
25
|
"url": "https://github.com/rhinobase/hono-openapi/issues"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"
|
|
28
|
+
"json-schema-walker": "^2.0.0"
|
|
28
29
|
},
|
|
29
30
|
"optionalDependencies": {
|
|
30
31
|
"@hono/arktype-validator": "^2.0.0",
|
|
32
|
+
"@hono/effect-validator": "^1.2.0",
|
|
31
33
|
"@hono/typebox-validator": "^0.2.6",
|
|
32
34
|
"@hono/valibot-validator": "^0.5.1",
|
|
33
35
|
"@hono/zod-validator": "^0.4.1",
|
|
34
36
|
"@sinclair/typebox": "^0.34.9",
|
|
35
37
|
"@valibot/to-json-schema": "^1.0.0-beta.3",
|
|
36
38
|
"arktype": "2.0.0-rc.25",
|
|
37
|
-
"
|
|
39
|
+
"effect": "^3.11.3",
|
|
40
|
+
"hono": "^4.6.13",
|
|
38
41
|
"openapi-types": "^12.1.3",
|
|
39
42
|
"valibot": "^1.0.0-beta.9",
|
|
40
43
|
"zod": "^3.23.8",
|
|
41
44
|
"zod-openapi": "^4.0.0"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
44
|
-
"@
|
|
47
|
+
"@apidevtools/json-schema-ref-parser": "^11.7.2",
|
|
48
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
49
|
+
"@types/json-schema": "^7.0.15"
|
|
45
50
|
},
|
|
46
51
|
"exports": {
|
|
47
52
|
".": {
|
|
@@ -93,6 +98,16 @@
|
|
|
93
98
|
"default": "./arktype.cjs.js",
|
|
94
99
|
"types": "./arktype.cjs.d.ts"
|
|
95
100
|
}
|
|
101
|
+
},
|
|
102
|
+
"./effect": {
|
|
103
|
+
"import": {
|
|
104
|
+
"default": "./effect.esm.js",
|
|
105
|
+
"types": "./effect.esm.d.ts"
|
|
106
|
+
},
|
|
107
|
+
"require": {
|
|
108
|
+
"default": "./effect.cjs.js",
|
|
109
|
+
"types": "./effect.cjs.d.ts"
|
|
110
|
+
}
|
|
96
111
|
}
|
|
97
112
|
},
|
|
98
113
|
"module": "./index.esm.js",
|
package/src/effect.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { Env, Input as HonoInput, MiddlewareHandler, ValidationTargets } from "hono";
|
|
3
|
+
import type { HasUndefined, ResolverResult } from "./types";
|
|
4
|
+
export declare function resolver<Type, Context>(schema: Schema.Schema<Type, Context, never>): ResolverResult;
|
|
5
|
+
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
|
+
in: HasUndefined<In> extends true ? {
|
|
7
|
+
[K in Target]?: K extends "json" ? In : HasUndefined<keyof ValidationTargets[K]> extends true ? {
|
|
8
|
+
[K2 in keyof In]?: ValidationTargets[K][K2];
|
|
9
|
+
} : {
|
|
10
|
+
[K2 in keyof In]: ValidationTargets[K][K2];
|
|
11
|
+
};
|
|
12
|
+
} : {
|
|
13
|
+
[K in Target]: K extends "json" ? In : HasUndefined<keyof ValidationTargets[K]> extends true ? {
|
|
14
|
+
[K2 in keyof In]?: ValidationTargets[K][K2];
|
|
15
|
+
} : {
|
|
16
|
+
[K2 in keyof In]: ValidationTargets[K][K2];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
out: {
|
|
20
|
+
[K in Target]: Out;
|
|
21
|
+
};
|
|
22
|
+
}, V extends I = I>(target: Target, schema: Schema.Schema<Type, Context, never>): MiddlewareHandler<E, P, V>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const allowedKeywords: string[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { JSONSchema4 } from "json-schema";
|
|
2
|
+
import type { OpenAPIV3 } from "openapi-types";
|
|
3
|
+
import type { Options } from "./types";
|
|
4
|
+
declare const convert: <T extends object = JSONSchema4>(schema: T, options?: Options) => Promise<OpenAPIV3.Document>;
|
|
5
|
+
export default convert;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JSONSchema, ParserOptions } from "@apidevtools/json-schema-ref-parser";
|
|
2
|
+
export type addPrefixToObject = {
|
|
3
|
+
[K in keyof JSONSchema as `x-${K}`]: JSONSchema[K];
|
|
4
|
+
};
|
|
5
|
+
export interface Options {
|
|
6
|
+
cloneSchema?: boolean;
|
|
7
|
+
dereference?: boolean;
|
|
8
|
+
convertUnreferencedDefinitions?: boolean;
|
|
9
|
+
dereferenceOptions?: ParserOptions | undefined;
|
|
10
|
+
}
|
|
11
|
+
type ExtendedJSONSchema = addPrefixToObject & JSONSchema;
|
|
12
|
+
export type SchemaType = ExtendedJSONSchema & {
|
|
13
|
+
example?: JSONSchema["examples"][number];
|
|
14
|
+
"x-patternProperties"?: JSONSchema["patternProperties"];
|
|
15
|
+
nullable?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type SchemaTypeKeys = keyof SchemaType;
|
|
18
|
+
export {};
|
package/typebox.cjs.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src
|
|
1
|
+
export * from "./src/typebox";
|
package/typebox.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@hono/typebox-validator"),r=require("
|
|
1
|
+
"use strict";var e=require("@hono/typebox-validator"),r=require("./index.cjs2.js"),a=require("@sinclair/typebox/value"),i=require("./utils.cjs.js");function t(e){return{builder:async a=>({schema:await r.convert(e)}),validator:r=>{a.Value.Parse(e,r)}}}require("json-schema-walker"),exports.resolver=t,exports.validator=function(r,a,s){const o=e.tbValidator(r,a,s);return Object.assign(o,{[i.uniqueSymbol]:{resolver:async e=>i.generateValidatorDocs(r,await t(a).builder(e))}})};
|
package/typebox.esm.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src
|
|
1
|
+
export * from "./src/typebox";
|
package/typebox.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{tbValidator as
|
|
1
|
+
import{tbValidator as r}from"@hono/typebox-validator";import{c as o}from"./index.esm2.js";import{Value as a}from"@sinclair/typebox/value";import{u as s,g as t}from"./utils.esm.js";import"json-schema-walker";function e(r){return{builder:async a=>({schema:await o(r)}),validator:o=>{a.Parse(r,o)}}}function i(o,a,i){const n=r(o,a,i);return Object.assign(n,{[s]:{resolver:async r=>t(o,await e(a).builder(r))}})}export{e as resolver,i as validator};
|
package/utils.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=Symbol("openapi");exports.generateValidatorDocs=async function(e,s){const
|
|
1
|
+
"use strict";const e=Symbol("openapi");exports.generateValidatorDocs=async function(e,s){const n=await s,o={};if("form"===e||"json"===e)o.requestBody={content:{["json"===e?"application/json":"application/x-www-form-urlencoded"]:{schema:n.schema}}};else{const s=[];if("$ref"in n.schema)s.push({in:e,name:n.schema.$ref,schema:n.schema});else for(const[o,c]of Object.entries(n.schema.properties??{}))s.push({in:e,name:o,schema:c,required:n.schema.required?.includes(o)});o.parameters=s}return{docs:o,components:n.components}},exports.uniqueSymbol=e;
|
package/utils.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=Symbol("openapi");async function s(e,s){const n=await s,o={};if("form"===e||"json"===e)o.requestBody={content:{["json"===e?"application/json":"application/x-www-form-urlencoded"]:{schema:n.schema}}};else{const s=[];if("$ref"in n.schema)s.push({in:e,name:n.schema.$ref,schema:n.schema});else for(const[o,
|
|
1
|
+
const e=Symbol("openapi");async function s(e,s){const n=await s,o={};if("form"===e||"json"===e)o.requestBody={content:{["json"===e?"application/json":"application/x-www-form-urlencoded"]:{schema:n.schema}}};else{const s=[];if("$ref"in n.schema)s.push({in:e,name:n.schema.$ref,schema:n.schema});else for(const[o,c]of Object.entries(n.schema.properties??{}))s.push({in:e,name:o,schema:c,required:n.schema.required?.includes(o)});o.parameters=s}return{docs:o,components:n.components}}export{s as g,e as u};
|
package/valibot.cjs.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src
|
|
1
|
+
export * from "./src/valibot";
|
package/valibot.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@hono/valibot-validator"),
|
|
1
|
+
"use strict";var e=require("@hono/valibot-validator"),r=require("./index.cjs2.js"),a=require("@valibot/to-json-schema"),i=require("valibot"),s=require("./utils.cjs.js");function t(e){return{builder:async i=>({schema:await r.convert(a.toJsonSchema(e))}),validator:async r=>{await i.parseAsync(e,r)}}}require("json-schema-walker"),exports.resolver=t,exports.validator=function(r,a,i){const o=e.vValidator(r,a,i);return Object.assign(o,{[s.uniqueSymbol]:{resolver:async e=>s.generateValidatorDocs(r,await t(a).builder(e))}})};
|
package/valibot.esm.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src
|
|
1
|
+
export * from "./src/valibot";
|
package/valibot.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{vValidator as o}from"@hono/valibot-validator";import a
|
|
1
|
+
import{vValidator as o}from"@hono/valibot-validator";import{c as a}from"./index.esm2.js";import{toJsonSchema as r}from"@valibot/to-json-schema";import{parseAsync as t}from"valibot";import{u as i,g as s}from"./utils.esm.js";import"json-schema-walker";function m(o){return{builder:async t=>({schema:await a(r(o))}),validator:async a=>{await t(o,a)}}}function e(a,r,t){const e=o(a,r,t);return Object.assign(e,{[i]:{resolver:async o=>s(a,await m(r).builder(o))}})}export{m as resolver,e as validator};
|
package/zod.cjs.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src
|
|
1
|
+
export * from "./src/zod";
|
package/zod.esm.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src
|
|
1
|
+
export * from "./src/zod";
|