@hono/zod-openapi 0.9.3 → 0.9.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/README.md CHANGED
@@ -51,6 +51,10 @@ const UserSchema = z
51
51
  .openapi('User')
52
52
  ```
53
53
 
54
+ > [!TIP]
55
+ > `UserSchema` schema will be registered as `"#/components/schemas/User"` refs in the OpenAPI document.
56
+ > If you want to register the schema as referenced components, use `.opanapi()` method.
57
+
54
58
  Next, create a route:
55
59
 
56
60
  ```ts
package/dist/index.d.mts CHANGED
@@ -2,10 +2,10 @@ import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
2
  import * as openapi3_ts_oas30 from 'openapi3-ts/oas30';
3
3
  import { RouteConfig, ZodMediaTypeObject, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
4
4
  import { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator';
5
- import { Env, Input, Handler, Context, Schema, Hono, ToSchema, TypedResponse } from 'hono';
5
+ import { Env, Context, TypedResponse, Input, Handler, Schema, Hono, ToSchema } from 'hono';
6
6
  import { MergeSchemaPath, MergePath } from 'hono/types';
7
7
  import { RemoveBlankRecord } from 'hono/utils/types';
8
- import { AnyZodObject, z, ZodSchema, ZodError, ZodType } from 'zod';
8
+ import { ZodError, AnyZodObject, z, ZodSchema, ZodType } from 'zod';
9
9
  export { z } from 'zod';
10
10
 
11
11
  type RequestTypes = {
@@ -100,4 +100,4 @@ declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"
100
100
  getRoutingPath(): RoutingPath<R["path"]>;
101
101
  };
102
102
 
103
- export { OpenAPIHono, OpenAPIHonoOptions, OpenAPIObjectConfigure, RouteHandler, RouteHook, createRoute };
103
+ export { type Hook, OpenAPIHono, type OpenAPIHonoOptions, type OpenAPIObjectConfigure, type RouteHandler, type RouteHook, createRoute };
package/dist/index.d.ts CHANGED
@@ -2,10 +2,10 @@ import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
2
  import * as openapi3_ts_oas30 from 'openapi3-ts/oas30';
3
3
  import { RouteConfig, ZodMediaTypeObject, OpenAPIRegistry, ZodRequestBody, ZodContentObject, ResponseConfig } from '@asteasolutions/zod-to-openapi';
4
4
  import { OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator';
5
- import { Env, Input, Handler, Context, Schema, Hono, ToSchema, TypedResponse } from 'hono';
5
+ import { Env, Context, TypedResponse, Input, Handler, Schema, Hono, ToSchema } from 'hono';
6
6
  import { MergeSchemaPath, MergePath } from 'hono/types';
7
7
  import { RemoveBlankRecord } from 'hono/utils/types';
8
- import { AnyZodObject, z, ZodSchema, ZodError, ZodType } from 'zod';
8
+ import { ZodError, AnyZodObject, z, ZodSchema, ZodType } from 'zod';
9
9
  export { z } from 'zod';
10
10
 
11
11
  type RequestTypes = {
@@ -100,4 +100,4 @@ declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"
100
100
  getRoutingPath(): RoutingPath<R["path"]>;
101
101
  };
102
102
 
103
- export { OpenAPIHono, OpenAPIHonoOptions, OpenAPIObjectConfigure, RouteHandler, RouteHook, createRoute };
103
+ export { type Hook, OpenAPIHono, type OpenAPIHonoOptions, type OpenAPIObjectConfigure, type RouteHandler, type RouteHook, createRoute };
package/dist/index.js CHANGED
@@ -105,6 +105,7 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
105
105
  });
106
106
  };
107
107
  route(path, app) {
108
+ const pathForOpenAPI = path.replaceAll(/:([^\/]+)/g, "{$1}");
108
109
  super.route(path, app);
109
110
  if (!(app instanceof _OpenAPIHono)) {
110
111
  return this;
@@ -116,12 +117,12 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
116
117
  case "route":
117
118
  return this.openAPIRegistry.registerPath({
118
119
  ...def.route,
119
- path: (0, import_url.mergePath)(path, def.route.path)
120
+ path: (0, import_url.mergePath)(pathForOpenAPI, def.route.path)
120
121
  });
121
122
  case "webhook":
122
123
  return this.openAPIRegistry.registerWebhook({
123
124
  ...def.webhook,
124
- path: (0, import_url.mergePath)(path, def.webhook.path)
125
+ path: (0, import_url.mergePath)(pathForOpenAPI, def.webhook.path)
125
126
  });
126
127
  case "schema":
127
128
  return this.openAPIRegistry.register(def.schema._def.openapi._internal.refId, def.schema);
package/dist/index.mjs CHANGED
@@ -83,6 +83,7 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
83
83
  });
84
84
  };
85
85
  route(path, app) {
86
+ const pathForOpenAPI = path.replaceAll(/:([^\/]+)/g, "{$1}");
86
87
  super.route(path, app);
87
88
  if (!(app instanceof _OpenAPIHono)) {
88
89
  return this;
@@ -94,12 +95,12 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
94
95
  case "route":
95
96
  return this.openAPIRegistry.registerPath({
96
97
  ...def.route,
97
- path: mergePath(path, def.route.path)
98
+ path: mergePath(pathForOpenAPI, def.route.path)
98
99
  });
99
100
  case "webhook":
100
101
  return this.openAPIRegistry.registerWebhook({
101
102
  ...def.webhook,
102
- path: mergePath(path, def.webhook.path)
103
+ path: mergePath(pathForOpenAPI, def.webhook.path)
103
104
  });
104
105
  case "schema":
105
106
  return this.openAPIRegistry.register(def.schema._def.openapi._internal.refId, def.schema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/zod-openapi",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "A wrapper class of Hono which supports OpenAPI.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -27,7 +27,6 @@
27
27
  }
28
28
  },
29
29
  "license": "MIT",
30
- "private": false,
31
30
  "publishConfig": {
32
31
  "registry": "https://registry.npmjs.org",
33
32
  "access": "public"
@@ -42,16 +41,18 @@
42
41
  "zod": "3.*"
43
42
  },
44
43
  "devDependencies": {
45
- "@hono/zod-validator": "^0.1.11",
46
- "hono": "^3.11.3",
44
+ "hono": "^3.11.7",
45
+ "jest": "^29.7.0",
46
+ "openapi3-ts": "^4.1.2",
47
+ "tsup": "^8.0.1",
47
48
  "vitest": "^1.0.1",
48
49
  "zod": "^3.22.1"
49
50
  },
50
51
  "dependencies": {
51
52
  "@asteasolutions/zod-to-openapi": "^5.5.0",
52
- "@hono/zod-validator": "^0.1.9"
53
+ "@hono/zod-validator": "^0.1.11"
53
54
  },
54
55
  "engines": {
55
56
  "node": ">=16.0.0"
56
57
  }
57
- }
58
+ }