hono-openapi 1.0.7 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.cjs +12 -4
- package/dist/index.d.cts +7 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +12 -5
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://npmjs.org/package/hono-openapi "View this project on NPM")
|
|
5
5
|
[](https://www.npmjs.com/package/hono-openapi)
|
|
6
6
|
|
|
7
|
-
This can automatically generate the OpenAPI specification for the Hono
|
|
7
|
+
This can automatically generate the OpenAPI specification for the Hono App using your validation schema, which can be used to generate client libraries, documentation, and more.
|
|
8
8
|
|
|
9
9
|
This lib supports all the validation libs which are [Standard Schema](https://standardschema.dev/) compliant.
|
|
10
10
|
|
|
@@ -19,5 +19,5 @@ Visit our [contributing docs](https://github.com/rhinobase/hono-openapi/blob/mai
|
|
|
19
19
|
|
|
20
20
|
## Credits
|
|
21
21
|
|
|
22
|
-
- The idea for this project was inspired by [ElysiaJS](https://elysiajs.com/) and their amazing work on generating [OpenAPI](https://elysiajs.com/
|
|
22
|
+
- The idea for this project was inspired by [ElysiaJS](https://elysiajs.com/) and their amazing work on generating [OpenAPI](https://elysiajs.com/patterns/openapi) specifications.
|
|
23
23
|
- 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/dist/index.cjs
CHANGED
|
@@ -61,6 +61,9 @@ function getPathContext(path) {
|
|
|
61
61
|
}
|
|
62
62
|
return context;
|
|
63
63
|
}
|
|
64
|
+
function clearSpecsContext() {
|
|
65
|
+
specsByPathContext.clear();
|
|
66
|
+
}
|
|
64
67
|
function mergeSpecs(route, ...specs) {
|
|
65
68
|
return specs.reduce(
|
|
66
69
|
(prev, spec) => {
|
|
@@ -213,6 +216,7 @@ async function generateSpecs(hono, options = DEFAULT_OPTIONS, c) {
|
|
|
213
216
|
}
|
|
214
217
|
};
|
|
215
218
|
const _documentation = ctx.options.documentation ?? {};
|
|
219
|
+
clearSpecsContext();
|
|
216
220
|
const paths = await generatePaths(hono, ctx);
|
|
217
221
|
for (const path in paths) {
|
|
218
222
|
for (const method in paths[path]) {
|
|
@@ -273,7 +277,10 @@ async function generatePaths(hono, ctx) {
|
|
|
273
277
|
}
|
|
274
278
|
}
|
|
275
279
|
const defaultOptionsForThisMethod = ctx.options.defaultOptions?.[routeMethod];
|
|
276
|
-
const { schema: routeSpecs, components = {} } = await getSpec(
|
|
280
|
+
const { schema: routeSpecs, components = {} } = await getSpec(
|
|
281
|
+
middlewareHandler,
|
|
282
|
+
defaultOptionsForThisMethod
|
|
283
|
+
);
|
|
277
284
|
ctx.components = mergeComponentsObjects(ctx.components, components);
|
|
278
285
|
registerSchemaPath({
|
|
279
286
|
route,
|
|
@@ -423,12 +430,12 @@ function loadVendor(vendor, fn) {
|
|
|
423
430
|
standardOpenapi.loadVendor(vendor, fn.toOpenAPISchema);
|
|
424
431
|
}
|
|
425
432
|
}
|
|
426
|
-
function resolver(schema,
|
|
433
|
+
function resolver(schema, userDefinedOptions) {
|
|
427
434
|
return {
|
|
428
435
|
vendor: schema["~standard"].vendor,
|
|
429
436
|
validate: schema["~standard"].validate,
|
|
430
|
-
toJSONSchema: () => standardJson.toJsonSchema(schema,
|
|
431
|
-
toOpenAPISchema: () => standardOpenapi.toOpenAPISchema(schema,
|
|
437
|
+
toJSONSchema: (customOptions) => standardJson.toJsonSchema(schema, { ...userDefinedOptions, ...customOptions }),
|
|
438
|
+
toOpenAPISchema: (customOptions) => standardOpenapi.toOpenAPISchema(schema, { ...userDefinedOptions, ...customOptions })
|
|
432
439
|
};
|
|
433
440
|
}
|
|
434
441
|
function validator(target, schema, hook, options) {
|
|
@@ -486,6 +493,7 @@ function describeResponse(handler, responses, options) {
|
|
|
486
493
|
}
|
|
487
494
|
|
|
488
495
|
exports.ALLOWED_METHODS = ALLOWED_METHODS;
|
|
496
|
+
exports.clearSpecsContext = clearSpecsContext;
|
|
489
497
|
exports.describeResponse = describeResponse;
|
|
490
498
|
exports.describeRoute = describeRoute;
|
|
491
499
|
exports.generateSpecs = generateSpecs;
|
package/dist/index.d.cts
CHANGED
|
@@ -2,9 +2,9 @@ import * as openapi_types from 'openapi-types';
|
|
|
2
2
|
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
3
|
import { Env, Input, Context, Next, MiddlewareHandler, ValidationTargets, Hono } from 'hono';
|
|
4
4
|
import { TypedResponse, RouterRoute, ValidationTargets as ValidationTargets$1, BlankEnv, Input as Input$1, BlankInput, Schema, BlankSchema, MiddlewareHandler as MiddlewareHandler$1 } from 'hono/types';
|
|
5
|
+
import { loadVendor as loadVendor$2, ToOpenAPISchemaContext } from '@standard-community/standard-openapi';
|
|
5
6
|
import { Hook } from '@hono/standard-validator';
|
|
6
7
|
import { loadVendor as loadVendor$1 } from '@standard-community/standard-json';
|
|
7
|
-
import { loadVendor as loadVendor$2 } from '@standard-community/standard-openapi';
|
|
8
8
|
import { StatusCode } from 'hono/utils/http-status';
|
|
9
9
|
import { JSONSchema7 } from 'json-schema';
|
|
10
10
|
|
|
@@ -74,11 +74,11 @@ declare function loadVendor(vendor: string, fn: {
|
|
|
74
74
|
* @param schema Validation schema
|
|
75
75
|
* @returns Resolver result
|
|
76
76
|
*/
|
|
77
|
-
declare function resolver<Schema extends StandardSchemaV1>(schema: Schema,
|
|
77
|
+
declare function resolver<Schema extends StandardSchemaV1>(schema: Schema, userDefinedOptions?: Record<string, unknown>): {
|
|
78
78
|
vendor: string;
|
|
79
79
|
validate: (value: unknown) => StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
|
|
80
|
-
toJSONSchema: () => JSONSchema7 | Promise<JSONSchema7>;
|
|
81
|
-
toOpenAPISchema: () => Promise<{
|
|
80
|
+
toJSONSchema: (customOptions?: Record<string, unknown>) => JSONSchema7 | Promise<JSONSchema7>;
|
|
81
|
+
toOpenAPISchema: (customOptions?: Record<string, unknown>) => Promise<{
|
|
82
82
|
schema: OpenAPIV3_1.SchemaObject;
|
|
83
83
|
components: OpenAPIV3_1.ComponentsObject | undefined;
|
|
84
84
|
}>;
|
|
@@ -133,6 +133,7 @@ declare function describeResponse<E extends Env, P extends string, I extends Inp
|
|
|
133
133
|
declare const uniqueSymbol: unique symbol;
|
|
134
134
|
declare const ALLOWED_METHODS: readonly ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
|
|
135
135
|
type AllowedMethods = (typeof ALLOWED_METHODS)[number];
|
|
136
|
+
declare function clearSpecsContext(): void;
|
|
136
137
|
declare function registerSchemaPath({ route, specs, paths, }: RegisterSchemaPathOptions): void;
|
|
137
138
|
declare function removeExcludedPaths(paths: OpenAPIV3_1.PathsObject, ctx: SpecContext): OpenAPIV3_1.PathsObject<{}, {}>;
|
|
138
139
|
|
|
@@ -143,9 +144,7 @@ type ResolverReturnType = ReturnType<typeof resolver> & {
|
|
|
143
144
|
* Override the media type of the request body, if not specified, it will be `application/json` for `json` target and `multipart/form-data` for `form` target.
|
|
144
145
|
*/
|
|
145
146
|
media?: string;
|
|
146
|
-
} &
|
|
147
|
-
[key: string]: unknown;
|
|
148
|
-
};
|
|
147
|
+
} & Partial<ToOpenAPISchemaContext>;
|
|
149
148
|
};
|
|
150
149
|
type HandlerUniqueProperty = (ResolverReturnType & {
|
|
151
150
|
target: keyof ValidationTargets$1;
|
|
@@ -278,4 +277,4 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
|
|
|
278
277
|
jsonSchemaDialect?: string;
|
|
279
278
|
}>;
|
|
280
279
|
|
|
281
|
-
export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SpecContext, describeResponse, describeRoute, generateSpecs, loadVendor, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
|
|
280
|
+
export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SpecContext, clearSpecsContext, describeResponse, describeRoute, generateSpecs, loadVendor, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import * as openapi_types from 'openapi-types';
|
|
|
2
2
|
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
3
|
import { Env, Input, Context, Next, MiddlewareHandler, ValidationTargets, Hono } from 'hono';
|
|
4
4
|
import { TypedResponse, RouterRoute, ValidationTargets as ValidationTargets$1, BlankEnv, Input as Input$1, BlankInput, Schema, BlankSchema, MiddlewareHandler as MiddlewareHandler$1 } from 'hono/types';
|
|
5
|
+
import { loadVendor as loadVendor$2, ToOpenAPISchemaContext } from '@standard-community/standard-openapi';
|
|
5
6
|
import { Hook } from '@hono/standard-validator';
|
|
6
7
|
import { loadVendor as loadVendor$1 } from '@standard-community/standard-json';
|
|
7
|
-
import { loadVendor as loadVendor$2 } from '@standard-community/standard-openapi';
|
|
8
8
|
import { StatusCode } from 'hono/utils/http-status';
|
|
9
9
|
import { JSONSchema7 } from 'json-schema';
|
|
10
10
|
|
|
@@ -74,11 +74,11 @@ declare function loadVendor(vendor: string, fn: {
|
|
|
74
74
|
* @param schema Validation schema
|
|
75
75
|
* @returns Resolver result
|
|
76
76
|
*/
|
|
77
|
-
declare function resolver<Schema extends StandardSchemaV1>(schema: Schema,
|
|
77
|
+
declare function resolver<Schema extends StandardSchemaV1>(schema: Schema, userDefinedOptions?: Record<string, unknown>): {
|
|
78
78
|
vendor: string;
|
|
79
79
|
validate: (value: unknown) => StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
|
|
80
|
-
toJSONSchema: () => JSONSchema7 | Promise<JSONSchema7>;
|
|
81
|
-
toOpenAPISchema: () => Promise<{
|
|
80
|
+
toJSONSchema: (customOptions?: Record<string, unknown>) => JSONSchema7 | Promise<JSONSchema7>;
|
|
81
|
+
toOpenAPISchema: (customOptions?: Record<string, unknown>) => Promise<{
|
|
82
82
|
schema: OpenAPIV3_1.SchemaObject;
|
|
83
83
|
components: OpenAPIV3_1.ComponentsObject | undefined;
|
|
84
84
|
}>;
|
|
@@ -133,6 +133,7 @@ declare function describeResponse<E extends Env, P extends string, I extends Inp
|
|
|
133
133
|
declare const uniqueSymbol: unique symbol;
|
|
134
134
|
declare const ALLOWED_METHODS: readonly ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
|
|
135
135
|
type AllowedMethods = (typeof ALLOWED_METHODS)[number];
|
|
136
|
+
declare function clearSpecsContext(): void;
|
|
136
137
|
declare function registerSchemaPath({ route, specs, paths, }: RegisterSchemaPathOptions): void;
|
|
137
138
|
declare function removeExcludedPaths(paths: OpenAPIV3_1.PathsObject, ctx: SpecContext): OpenAPIV3_1.PathsObject<{}, {}>;
|
|
138
139
|
|
|
@@ -143,9 +144,7 @@ type ResolverReturnType = ReturnType<typeof resolver> & {
|
|
|
143
144
|
* Override the media type of the request body, if not specified, it will be `application/json` for `json` target and `multipart/form-data` for `form` target.
|
|
144
145
|
*/
|
|
145
146
|
media?: string;
|
|
146
|
-
} &
|
|
147
|
-
[key: string]: unknown;
|
|
148
|
-
};
|
|
147
|
+
} & Partial<ToOpenAPISchemaContext>;
|
|
149
148
|
};
|
|
150
149
|
type HandlerUniqueProperty = (ResolverReturnType & {
|
|
151
150
|
target: keyof ValidationTargets$1;
|
|
@@ -278,4 +277,4 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
|
|
|
278
277
|
jsonSchemaDialect?: string;
|
|
279
278
|
}>;
|
|
280
279
|
|
|
281
|
-
export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SpecContext, describeResponse, describeRoute, generateSpecs, loadVendor, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
|
|
280
|
+
export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SpecContext, clearSpecsContext, describeResponse, describeRoute, generateSpecs, loadVendor, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
|
package/dist/index.js
CHANGED
|
@@ -59,6 +59,9 @@ function getPathContext(path) {
|
|
|
59
59
|
}
|
|
60
60
|
return context;
|
|
61
61
|
}
|
|
62
|
+
function clearSpecsContext() {
|
|
63
|
+
specsByPathContext.clear();
|
|
64
|
+
}
|
|
62
65
|
function mergeSpecs(route, ...specs) {
|
|
63
66
|
return specs.reduce(
|
|
64
67
|
(prev, spec) => {
|
|
@@ -211,6 +214,7 @@ async function generateSpecs(hono, options = DEFAULT_OPTIONS, c) {
|
|
|
211
214
|
}
|
|
212
215
|
};
|
|
213
216
|
const _documentation = ctx.options.documentation ?? {};
|
|
217
|
+
clearSpecsContext();
|
|
214
218
|
const paths = await generatePaths(hono, ctx);
|
|
215
219
|
for (const path in paths) {
|
|
216
220
|
for (const method in paths[path]) {
|
|
@@ -271,7 +275,10 @@ async function generatePaths(hono, ctx) {
|
|
|
271
275
|
}
|
|
272
276
|
}
|
|
273
277
|
const defaultOptionsForThisMethod = ctx.options.defaultOptions?.[routeMethod];
|
|
274
|
-
const { schema: routeSpecs, components = {} } = await getSpec(
|
|
278
|
+
const { schema: routeSpecs, components = {} } = await getSpec(
|
|
279
|
+
middlewareHandler,
|
|
280
|
+
defaultOptionsForThisMethod
|
|
281
|
+
);
|
|
275
282
|
ctx.components = mergeComponentsObjects(ctx.components, components);
|
|
276
283
|
registerSchemaPath({
|
|
277
284
|
route,
|
|
@@ -421,12 +428,12 @@ function loadVendor(vendor, fn) {
|
|
|
421
428
|
loadVendor$2(vendor, fn.toOpenAPISchema);
|
|
422
429
|
}
|
|
423
430
|
}
|
|
424
|
-
function resolver(schema,
|
|
431
|
+
function resolver(schema, userDefinedOptions) {
|
|
425
432
|
return {
|
|
426
433
|
vendor: schema["~standard"].vendor,
|
|
427
434
|
validate: schema["~standard"].validate,
|
|
428
|
-
toJSONSchema: () => toJsonSchema(schema,
|
|
429
|
-
toOpenAPISchema: () => toOpenAPISchema(schema,
|
|
435
|
+
toJSONSchema: (customOptions) => toJsonSchema(schema, { ...userDefinedOptions, ...customOptions }),
|
|
436
|
+
toOpenAPISchema: (customOptions) => toOpenAPISchema(schema, { ...userDefinedOptions, ...customOptions })
|
|
430
437
|
};
|
|
431
438
|
}
|
|
432
439
|
function validator(target, schema, hook, options) {
|
|
@@ -483,4 +490,4 @@ function describeResponse(handler, responses, options) {
|
|
|
483
490
|
});
|
|
484
491
|
}
|
|
485
492
|
|
|
486
|
-
export { ALLOWED_METHODS, describeResponse, describeRoute, generateSpecs, loadVendor, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
|
|
493
|
+
export { ALLOWED_METHODS, clearSpecsContext, describeResponse, describeRoute, generateSpecs, loadVendor, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
|
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": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -25,8 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/rhinobase/hono-openapi.git"
|
|
29
|
-
"directory": "packages/core"
|
|
28
|
+
"url": "git+https://github.com/rhinobase/hono-openapi.git"
|
|
30
29
|
},
|
|
31
30
|
"bugs": {
|
|
32
31
|
"url": "https://github.com/rhinobase/hono-openapi/issues"
|
|
@@ -43,8 +42,8 @@
|
|
|
43
42
|
},
|
|
44
43
|
"peerDependencies": {
|
|
45
44
|
"@hono/standard-validator": "^0.1.2",
|
|
46
|
-
"@standard-community/standard-json": "^0.3.
|
|
47
|
-
"@standard-community/standard-openapi": "^0.2.
|
|
45
|
+
"@standard-community/standard-json": "^0.3.5",
|
|
46
|
+
"@standard-community/standard-openapi": "^0.2.8",
|
|
48
47
|
"@types/json-schema": "^7.0.15",
|
|
49
48
|
"hono": "^4.8.3",
|
|
50
49
|
"openapi-types": "^12.1.3"
|
|
@@ -66,8 +65,11 @@
|
|
|
66
65
|
"husky": "^9.1.7",
|
|
67
66
|
"is-ci": "^4.1.0",
|
|
68
67
|
"nano-staged": "^0.8.0",
|
|
68
|
+
"pkg-pr-new": "^0.0.60",
|
|
69
69
|
"pkgroll": "^2.13.1",
|
|
70
|
+
"typebox": "^1.0.17",
|
|
70
71
|
"typescript": "^5.8.3",
|
|
72
|
+
"sury": "^10.0.0",
|
|
71
73
|
"valibot": "^1.1.0",
|
|
72
74
|
"vitest": "^3.2.4",
|
|
73
75
|
"zod": "^3.23.8",
|
|
@@ -75,6 +77,7 @@
|
|
|
75
77
|
},
|
|
76
78
|
"scripts": {
|
|
77
79
|
"build": "pkgroll --clean-dist",
|
|
80
|
+
"lint": "biome check .",
|
|
78
81
|
"format": "biome check --write .",
|
|
79
82
|
"test": "vitest"
|
|
80
83
|
}
|