hono-openapi 1.0.4 → 1.0.5

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
@@ -141,6 +141,7 @@ function removeExcludedPaths(paths, ctx) {
141
141
  if (isPathExcluded && !(key.includes("*") && !key.includes("{")) && isStaticFileExcluded && value != null) {
142
142
  for (const method of Object.keys(value)) {
143
143
  const schema = value[method];
144
+ if (schema == null) continue;
144
145
  if (key.includes("{")) {
145
146
  if (!schema.parameters) schema.parameters = [];
146
147
  const pathParameters = key.split("/").filter(
@@ -378,9 +379,12 @@ function generateParameters(target, schema) {
378
379
  in: target === "param" ? "path" : target,
379
380
  name: key,
380
381
  // @ts-expect-error
381
- schema: value,
382
- required: schema.required?.includes(key)
382
+ schema: value
383
383
  };
384
+ const isRequired = schema.required?.includes(key);
385
+ if (isRequired) {
386
+ def.required = true;
387
+ }
384
388
  if (def.schema && "description" in def.schema && def.schema.description) {
385
389
  def.description = def.schema.description;
386
390
  def.schema.description = void 0;
@@ -392,7 +396,7 @@ function generateParameters(target, schema) {
392
396
  function mergeComponentsObjects(...components) {
393
397
  return components.reduce(
394
398
  (prev, component, index) => {
395
- if (!component || index === 0) return prev;
399
+ if (component == null || index === 0) return prev;
396
400
  if (prev.schemas && Object.keys(prev.schemas).length > 0 || component.schemas && Object.keys(component.schemas).length > 0) {
397
401
  prev.schemas = {
398
402
  ...prev.schemas,
@@ -411,6 +415,14 @@ function mergeComponentsObjects(...components) {
411
415
  );
412
416
  }
413
417
 
418
+ function loadVendor(vendor, fn) {
419
+ if (fn.toJSONSchema) {
420
+ standardJson.loadVendor(vendor, fn.toJSONSchema);
421
+ }
422
+ if (fn.toOpenAPISchema) {
423
+ standardOpenapi.loadVendor(vendor, fn.toOpenAPISchema);
424
+ }
425
+ }
414
426
  function resolver(schema, options) {
415
427
  return {
416
428
  vendor: schema["~standard"].vendor,
@@ -477,6 +489,7 @@ exports.ALLOWED_METHODS = ALLOWED_METHODS;
477
489
  exports.describeResponse = describeResponse;
478
490
  exports.describeRoute = describeRoute;
479
491
  exports.generateSpecs = generateSpecs;
492
+ exports.loadVendor = loadVendor;
480
493
  exports.openAPIRouteHandler = openAPIRouteHandler;
481
494
  exports.registerSchemaPath = registerSchemaPath;
482
495
  exports.removeExcludedPaths = removeExcludedPaths;
package/dist/index.d.cts CHANGED
@@ -2,9 +2,11 @@ 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 * as json_schema from 'json-schema';
6
5
  import { Hook } from '@hono/standard-validator';
6
+ import { loadVendor as loadVendor$1 } from '@standard-community/standard-json';
7
+ import { loadVendor as loadVendor$2 } from '@standard-community/standard-openapi';
7
8
  import { StatusCode } from 'hono/utils/http-status';
9
+ import { JSONSchema7 } from 'json-schema';
8
10
 
9
11
  /** The Standard Schema interface. */
10
12
  interface StandardSchemaV1<Input = unknown, Output = Input> {
@@ -63,6 +65,10 @@ declare namespace StandardSchemaV1 {
63
65
  export { };
64
66
  }
65
67
 
68
+ declare function loadVendor(vendor: string, fn: {
69
+ toJSONSchema?: Parameters<typeof loadVendor$1>[1];
70
+ toOpenAPISchema?: Parameters<typeof loadVendor$2>[1];
71
+ }): void;
66
72
  /**
67
73
  * Generate a resolver for a validation schema
68
74
  * @param schema Validation schema
@@ -71,7 +77,7 @@ declare namespace StandardSchemaV1 {
71
77
  declare function resolver<Schema extends StandardSchemaV1>(schema: Schema, options?: Record<string, unknown>): {
72
78
  vendor: string;
73
79
  validate: (value: unknown) => StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
74
- toJSONSchema: () => Promise<json_schema.JSONSchema7>;
80
+ toJSONSchema: () => JSONSchema7 | Promise<JSONSchema7>;
75
81
  toOpenAPISchema: () => Promise<{
76
82
  schema: OpenAPIV3_1.SchemaObject;
77
83
  components: OpenAPIV3_1.ComponentsObject | undefined;
@@ -272,4 +278,4 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
272
278
  jsonSchemaDialect?: string;
273
279
  }>;
274
280
 
275
- export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SpecContext, describeResponse, describeRoute, generateSpecs, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
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 };
package/dist/index.d.ts CHANGED
@@ -2,9 +2,11 @@ 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 * as json_schema from 'json-schema';
6
5
  import { Hook } from '@hono/standard-validator';
6
+ import { loadVendor as loadVendor$1 } from '@standard-community/standard-json';
7
+ import { loadVendor as loadVendor$2 } from '@standard-community/standard-openapi';
7
8
  import { StatusCode } from 'hono/utils/http-status';
9
+ import { JSONSchema7 } from 'json-schema';
8
10
 
9
11
  /** The Standard Schema interface. */
10
12
  interface StandardSchemaV1<Input = unknown, Output = Input> {
@@ -63,6 +65,10 @@ declare namespace StandardSchemaV1 {
63
65
  export { };
64
66
  }
65
67
 
68
+ declare function loadVendor(vendor: string, fn: {
69
+ toJSONSchema?: Parameters<typeof loadVendor$1>[1];
70
+ toOpenAPISchema?: Parameters<typeof loadVendor$2>[1];
71
+ }): void;
66
72
  /**
67
73
  * Generate a resolver for a validation schema
68
74
  * @param schema Validation schema
@@ -71,7 +77,7 @@ declare namespace StandardSchemaV1 {
71
77
  declare function resolver<Schema extends StandardSchemaV1>(schema: Schema, options?: Record<string, unknown>): {
72
78
  vendor: string;
73
79
  validate: (value: unknown) => StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
74
- toJSONSchema: () => Promise<json_schema.JSONSchema7>;
80
+ toJSONSchema: () => JSONSchema7 | Promise<JSONSchema7>;
75
81
  toOpenAPISchema: () => Promise<{
76
82
  schema: OpenAPIV3_1.SchemaObject;
77
83
  components: OpenAPIV3_1.ComponentsObject | undefined;
@@ -272,4 +278,4 @@ declare function generateSpecs<E extends Env = BlankEnv, P extends string = stri
272
278
  jsonSchemaDialect?: string;
273
279
  }>;
274
280
 
275
- export { ALLOWED_METHODS, type AllowedMethods, type DescribeRouteOptions, type GenerateSpecOptions, type HandlerUniqueProperty, type PromiseOr, type RegisterSchemaPathOptions, type ResolverReturnType, type SpecContext, describeResponse, describeRoute, generateSpecs, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
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 };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { sValidator } from '@hono/standard-validator';
2
- import { toJsonSchema } from '@standard-community/standard-json';
3
- import { toOpenAPISchema } from '@standard-community/standard-openapi';
2
+ import { loadVendor as loadVendor$1, toJsonSchema } from '@standard-community/standard-json';
3
+ import { loadVendor as loadVendor$2, toOpenAPISchema } from '@standard-community/standard-openapi';
4
4
 
5
5
  const uniqueSymbol = Symbol("openapi");
6
6
  const ALLOWED_METHODS = [
@@ -139,6 +139,7 @@ function removeExcludedPaths(paths, ctx) {
139
139
  if (isPathExcluded && !(key.includes("*") && !key.includes("{")) && isStaticFileExcluded && value != null) {
140
140
  for (const method of Object.keys(value)) {
141
141
  const schema = value[method];
142
+ if (schema == null) continue;
142
143
  if (key.includes("{")) {
143
144
  if (!schema.parameters) schema.parameters = [];
144
145
  const pathParameters = key.split("/").filter(
@@ -376,9 +377,12 @@ function generateParameters(target, schema) {
376
377
  in: target === "param" ? "path" : target,
377
378
  name: key,
378
379
  // @ts-expect-error
379
- schema: value,
380
- required: schema.required?.includes(key)
380
+ schema: value
381
381
  };
382
+ const isRequired = schema.required?.includes(key);
383
+ if (isRequired) {
384
+ def.required = true;
385
+ }
382
386
  if (def.schema && "description" in def.schema && def.schema.description) {
383
387
  def.description = def.schema.description;
384
388
  def.schema.description = void 0;
@@ -390,7 +394,7 @@ function generateParameters(target, schema) {
390
394
  function mergeComponentsObjects(...components) {
391
395
  return components.reduce(
392
396
  (prev, component, index) => {
393
- if (!component || index === 0) return prev;
397
+ if (component == null || index === 0) return prev;
394
398
  if (prev.schemas && Object.keys(prev.schemas).length > 0 || component.schemas && Object.keys(component.schemas).length > 0) {
395
399
  prev.schemas = {
396
400
  ...prev.schemas,
@@ -409,6 +413,14 @@ function mergeComponentsObjects(...components) {
409
413
  );
410
414
  }
411
415
 
416
+ function loadVendor(vendor, fn) {
417
+ if (fn.toJSONSchema) {
418
+ loadVendor$1(vendor, fn.toJSONSchema);
419
+ }
420
+ if (fn.toOpenAPISchema) {
421
+ loadVendor$2(vendor, fn.toOpenAPISchema);
422
+ }
423
+ }
412
424
  function resolver(schema, options) {
413
425
  return {
414
426
  vendor: schema["~standard"].vendor,
@@ -471,4 +483,4 @@ function describeResponse(handler, responses, options) {
471
483
  });
472
484
  }
473
485
 
474
- export { ALLOWED_METHODS, describeResponse, describeRoute, generateSpecs, openAPIRouteHandler, registerSchemaPath, removeExcludedPaths, resolver, uniqueSymbol, validator };
486
+ export { ALLOWED_METHODS, 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",
4
+ "version": "1.0.5",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -43,8 +43,8 @@
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@hono/standard-validator": "^0.1.2",
46
- "@standard-community/standard-json": "^0.3.0-rc.4",
47
- "@standard-community/standard-openapi": "^0.2.0-rc.1",
46
+ "@standard-community/standard-json": "^0.3.1",
47
+ "@standard-community/standard-openapi": "^0.2.3",
48
48
  "@types/json-schema": "^7.0.15",
49
49
  "hono": "^4.8.3",
50
50
  "openapi-types": "^12.1.3"