hono-openapi 1.0.8 → 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 CHANGED
@@ -4,7 +4,7 @@
4
4
  [![npm version](https://img.shields.io/npm/v/hono-openapi.svg)](https://npmjs.org/package/hono-openapi "View this project on NPM")
5
5
  [![npm downloads](https://img.shields.io/npm/dm/hono-openapi)](https://www.npmjs.com/package/hono-openapi)
6
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.
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/recipe/openapi.html) specifications.
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]) {
@@ -426,12 +430,12 @@ function loadVendor(vendor, fn) {
426
430
  standardOpenapi.loadVendor(vendor, fn.toOpenAPISchema);
427
431
  }
428
432
  }
429
- function resolver(schema, options) {
433
+ function resolver(schema, userDefinedOptions) {
430
434
  return {
431
435
  vendor: schema["~standard"].vendor,
432
436
  validate: schema["~standard"].validate,
433
- toJSONSchema: () => standardJson.toJsonSchema(schema, options),
434
- toOpenAPISchema: () => standardOpenapi.toOpenAPISchema(schema, options)
437
+ toJSONSchema: (customOptions) => standardJson.toJsonSchema(schema, { ...userDefinedOptions, ...customOptions }),
438
+ toOpenAPISchema: (customOptions) => standardOpenapi.toOpenAPISchema(schema, { ...userDefinedOptions, ...customOptions })
435
439
  };
436
440
  }
437
441
  function validator(target, schema, hook, options) {
@@ -489,6 +493,7 @@ function describeResponse(handler, responses, options) {
489
493
  }
490
494
 
491
495
  exports.ALLOWED_METHODS = ALLOWED_METHODS;
496
+ exports.clearSpecsContext = clearSpecsContext;
492
497
  exports.describeResponse = describeResponse;
493
498
  exports.describeRoute = describeRoute;
494
499
  exports.generateSpecs = generateSpecs;
package/dist/index.d.cts CHANGED
@@ -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, options?: Record<string, unknown>): {
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
 
@@ -276,4 +277,4 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
276
277
  jsonSchemaDialect?: string;
277
278
  }>;
278
279
 
279
- 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
@@ -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, options?: Record<string, unknown>): {
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
 
@@ -276,4 +277,4 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
276
277
  jsonSchemaDialect?: string;
277
278
  }>;
278
279
 
279
- 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]) {
@@ -424,12 +428,12 @@ function loadVendor(vendor, fn) {
424
428
  loadVendor$2(vendor, fn.toOpenAPISchema);
425
429
  }
426
430
  }
427
- function resolver(schema, options) {
431
+ function resolver(schema, userDefinedOptions) {
428
432
  return {
429
433
  vendor: schema["~standard"].vendor,
430
434
  validate: schema["~standard"].validate,
431
- toJSONSchema: () => toJsonSchema(schema, options),
432
- toOpenAPISchema: () => toOpenAPISchema(schema, options)
435
+ toJSONSchema: (customOptions) => toJsonSchema(schema, { ...userDefinedOptions, ...customOptions }),
436
+ toOpenAPISchema: (customOptions) => toOpenAPISchema(schema, { ...userDefinedOptions, ...customOptions })
433
437
  };
434
438
  }
435
439
  function validator(target, schema, hook, options) {
@@ -486,4 +490,4 @@ function describeResponse(handler, responses, options) {
486
490
  });
487
491
  }
488
492
 
489
- 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.8",
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.1",
47
- "@standard-community/standard-openapi": "^0.2.4",
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
  }