hono-openapi 0.5.0-rc.0 → 0.5.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -184,6 +184,14 @@ const DEFAULT_OPTIONS = {
184
184
  excludeMethods: ["OPTIONS"],
185
185
  excludeTags: []
186
186
  };
187
+ function openAPIRouteHandler(hono, options) {
188
+ let specs;
189
+ return async (c) => {
190
+ if (specs) return c.json(specs);
191
+ specs = await generateSpecs(hono, options, c);
192
+ return c.json(specs);
193
+ };
194
+ }
187
195
  async function generateSpecs(hono, options = DEFAULT_OPTIONS, c) {
188
196
  const ctx = {
189
197
  components: {},
@@ -403,6 +411,7 @@ function describeRoute(spec) {
403
411
  exports.ALLOWED_METHODS = ALLOWED_METHODS;
404
412
  exports.describeRoute = describeRoute;
405
413
  exports.generateSpecs = generateSpecs;
414
+ exports.openAPIRouteHandler = openAPIRouteHandler;
406
415
  exports.registerSchemaPath = registerSchemaPath;
407
416
  exports.removeExcludedPaths = removeExcludedPaths;
408
417
  exports.resolver = resolver;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as openapi_types from 'openapi-types';
2
2
  import { OpenAPIV3_1 } from 'openapi-types';
3
3
  import { MiddlewareHandler, ValidationTargets, Env, Input, Context, Hono } from 'hono';
4
- import { ValidationTargets as ValidationTargets$1, RouterRoute, BlankEnv, Input as Input$1, BlankInput, Schema, BlankSchema } from 'hono/types';
4
+ import { ValidationTargets as ValidationTargets$1, RouterRoute, BlankEnv, Input as Input$1, BlankInput, Schema, BlankSchema, MiddlewareHandler as MiddlewareHandler$1 } from 'hono/types';
5
5
  import { Hook } from '@hono/standard-validator';
6
6
 
7
7
  // ==================================================================================================
@@ -354,6 +354,13 @@ type RegisterSchemaPathOptions = {
354
354
  paths: Partial<OpenAPIV3_1.PathsObject>;
355
355
  };
356
356
 
357
+ /**
358
+ * Route handler for OpenAPI specs
359
+ * @param hono Instance of Hono
360
+ * @param options Options for generating OpenAPI specs
361
+ * @returns Middleware handler for OpenAPI specs
362
+ */
363
+ declare function openAPIRouteHandler<E extends Env = BlankEnv, P extends string = string, I extends Input$1 = BlankInput, S extends Schema = BlankSchema>(hono: Hono<E, S, P>, options?: GenerateSpecOptions): MiddlewareHandler$1<E, P, I>;
357
364
  /**
358
365
  * Generate OpenAPI specs for the given Hono instance
359
366
  * @param hono Instance of Hono
@@ -410,4 +417,4 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
410
417
  jsonSchemaDialect?: string;
411
418
  }>;
412
419
 
413
- export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SanitizedGenerateSpecOptions, describeRoute, generateSpecs, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
420
+ export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SanitizedGenerateSpecOptions, describeRoute, generateSpecs, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as openapi_types from 'openapi-types';
2
2
  import { OpenAPIV3_1 } from 'openapi-types';
3
3
  import { MiddlewareHandler, ValidationTargets, Env, Input, Context, Hono } from 'hono';
4
- import { ValidationTargets as ValidationTargets$1, RouterRoute, BlankEnv, Input as Input$1, BlankInput, Schema, BlankSchema } from 'hono/types';
4
+ import { ValidationTargets as ValidationTargets$1, RouterRoute, BlankEnv, Input as Input$1, BlankInput, Schema, BlankSchema, MiddlewareHandler as MiddlewareHandler$1 } from 'hono/types';
5
5
  import { Hook } from '@hono/standard-validator';
6
6
 
7
7
  // ==================================================================================================
@@ -354,6 +354,13 @@ type RegisterSchemaPathOptions = {
354
354
  paths: Partial<OpenAPIV3_1.PathsObject>;
355
355
  };
356
356
 
357
+ /**
358
+ * Route handler for OpenAPI specs
359
+ * @param hono Instance of Hono
360
+ * @param options Options for generating OpenAPI specs
361
+ * @returns Middleware handler for OpenAPI specs
362
+ */
363
+ declare function openAPIRouteHandler<E extends Env = BlankEnv, P extends string = string, I extends Input$1 = BlankInput, S extends Schema = BlankSchema>(hono: Hono<E, S, P>, options?: GenerateSpecOptions): MiddlewareHandler$1<E, P, I>;
357
364
  /**
358
365
  * Generate OpenAPI specs for the given Hono instance
359
366
  * @param hono Instance of Hono
@@ -410,4 +417,4 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
410
417
  jsonSchemaDialect?: string;
411
418
  }>;
412
419
 
413
- export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SanitizedGenerateSpecOptions, describeRoute, generateSpecs, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
420
+ export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SanitizedGenerateSpecOptions, describeRoute, generateSpecs, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
package/dist/index.js CHANGED
@@ -182,6 +182,14 @@ const DEFAULT_OPTIONS = {
182
182
  excludeMethods: ["OPTIONS"],
183
183
  excludeTags: []
184
184
  };
185
+ function openAPIRouteHandler(hono, options) {
186
+ let specs;
187
+ return async (c) => {
188
+ if (specs) return c.json(specs);
189
+ specs = await generateSpecs(hono, options, c);
190
+ return c.json(specs);
191
+ };
192
+ }
185
193
  async function generateSpecs(hono, options = DEFAULT_OPTIONS, c) {
186
194
  const ctx = {
187
195
  components: {},
@@ -398,4 +406,4 @@ function describeRoute(spec) {
398
406
  });
399
407
  }
400
408
 
401
- export { ALLOWED_METHODS, describeRoute, generateSpecs, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
409
+ export { ALLOWED_METHODS, describeRoute, generateSpecs, 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": "0.5.0-rc.0",
4
+ "version": "0.5.0-rc.1",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",