@hono/zod-openapi 1.0.1 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @hono/zod-openapi
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1353](https://github.com/honojs/middleware/pull/1353) [`f42a557f47f6e9cba1cbc40ad0cd8c0d798146c0`](https://github.com/honojs/middleware/commit/f42a557f47f6e9cba1cbc40ad0cd8c0d798146c0) Thanks [@yumuranaoki](https://github.com/yumuranaoki)! - Add optional generator options parameter to doc middleware
8
+
9
+ ## 1.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1320](https://github.com/honojs/middleware/pull/1320) [`e835cf6183fb4717cfdbe156d9b3d423625a0e15`](https://github.com/honojs/middleware/commit/e835cf6183fb4717cfdbe156d9b3d423625a0e15) Thanks [@yusukebe](https://github.com/yusukebe)! - fix: correct importing `zod`
14
+
3
15
  ## 1.0.1
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -309,12 +309,19 @@ You can generate OpenAPI v3.1 spec using the following methods:
309
309
 
310
310
  ```ts
311
311
  app.doc31('/docs', { openapi: '3.1.0', info: { title: 'foo', version: '1' } }) // new endpoint
312
- app.getOpenAPI31Document({
313
- openapi: '3.1.0',
314
- info: { title: 'foo', version: '1' },
315
- }) // schema object
312
+ app.getOpenAPI31Document(
313
+ {
314
+ openapi: '3.1.0',
315
+ info: { title: 'foo', version: '1' },
316
+ }, // OpenAPI object config
317
+ {
318
+ unionPreferredType: 'oneOf',
319
+ } // Generator options
320
+ ) // schema object
316
321
  ```
317
322
 
323
+ The second parameter is optional and accepts generator options as supported by the `@asteasolutions/zod-to-openapi` library. Refer to their documentation for the complete list of available options and their usage.
324
+
318
325
  ### The Registry
319
326
 
320
327
  You can access the [`OpenAPIRegistry`](https://github.com/asteasolutions/zod-to-openapi#the-registry) object via `app.openAPIRegistry`:
package/dist/index.cjs CHANGED
@@ -23,14 +23,14 @@ __export(index_exports, {
23
23
  OpenAPIHono: () => OpenAPIHono,
24
24
  createRoute: () => createRoute,
25
25
  extendZodWithOpenApi: () => import_zod_to_openapi.extendZodWithOpenApi,
26
- z: () => import_v4.z
26
+ z: () => import_zod.z
27
27
  });
28
28
  module.exports = __toCommonJS(index_exports);
29
29
  var import_zod_to_openapi = require("@asteasolutions/zod-to-openapi");
30
30
  var import_zod_validator = require("@hono/zod-validator");
31
31
  var import_hono = require("hono");
32
32
  var import_url = require("hono/utils/url");
33
- var import_v4 = require("zod/v4");
33
+ var import_zod = require("zod");
34
34
  var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
35
35
  openAPIRegistry;
36
36
  defaultHook;
@@ -98,7 +98,7 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
98
98
  continue;
99
99
  }
100
100
  const schema = bodyContent[mediaType]["schema"];
101
- if (!(schema instanceof import_v4.ZodType)) {
101
+ if (!(schema instanceof import_zod.ZodType)) {
102
102
  continue;
103
103
  }
104
104
  if (isJSONContentType(mediaType)) {
@@ -147,32 +147,34 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
147
147
  );
148
148
  return this;
149
149
  };
150
- getOpenAPIDocument = (config) => {
151
- const generator = new import_zod_to_openapi.OpenApiGeneratorV3(this.openAPIRegistry.definitions);
152
- const document = generator.generateDocument(config);
150
+ getOpenAPIDocument = (objectConfig, generatorConfig) => {
151
+ const generator = new import_zod_to_openapi.OpenApiGeneratorV3(this.openAPIRegistry.definitions, generatorConfig);
152
+ const document = generator.generateDocument(objectConfig);
153
153
  return this._basePath ? addBasePathToDocument(document, this._basePath) : document;
154
154
  };
155
- getOpenAPI31Document = (config) => {
156
- const generator = new import_zod_to_openapi.OpenApiGeneratorV31(this.openAPIRegistry.definitions);
157
- const document = generator.generateDocument(config);
155
+ getOpenAPI31Document = (objectConfig, generatorConfig) => {
156
+ const generator = new import_zod_to_openapi.OpenApiGeneratorV31(this.openAPIRegistry.definitions, generatorConfig);
157
+ const document = generator.generateDocument(objectConfig);
158
158
  return this._basePath ? addBasePathToDocument(document, this._basePath) : document;
159
159
  };
160
- doc = (path, configure) => {
160
+ doc = (path, configureObject, configureGenerator) => {
161
161
  return this.get(path, (c) => {
162
- const config = typeof configure === "function" ? configure(c) : configure;
162
+ const objectConfig = typeof configureObject === "function" ? configureObject(c) : configureObject;
163
+ const generatorConfig = typeof configureGenerator === "function" ? configureGenerator(c) : configureGenerator;
163
164
  try {
164
- const document = this.getOpenAPIDocument(config);
165
+ const document = this.getOpenAPIDocument(objectConfig, generatorConfig);
165
166
  return c.json(document);
166
167
  } catch (e) {
167
168
  return c.json(e, 500);
168
169
  }
169
170
  });
170
171
  };
171
- doc31 = (path, configure) => {
172
+ doc31 = (path, configureObject, configureGenerator) => {
172
173
  return this.get(path, (c) => {
173
- const config = typeof configure === "function" ? configure(c) : configure;
174
+ const objectConfig = typeof configureObject === "function" ? configureObject(c) : configureObject;
175
+ const generatorConfig = typeof configureGenerator === "function" ? configureGenerator(c) : configureGenerator;
174
176
  try {
175
- const document = this.getOpenAPI31Document(config);
177
+ const document = this.getOpenAPI31Document(objectConfig, generatorConfig);
176
178
  return c.json(document);
177
179
  } catch (e) {
178
180
  return c.json(e, 500);
@@ -244,7 +246,7 @@ var createRoute = (routeConfig) => {
244
246
  };
245
247
  return Object.defineProperty(route, "getRoutingPath", { enumerable: false });
246
248
  };
247
- (0, import_zod_to_openapi.extendZodWithOpenApi)(import_v4.z);
249
+ (0, import_zod_to_openapi.extendZodWithOpenApi)(import_zod.z);
248
250
  function addBasePathToDocument(document, basePath) {
249
251
  const updatedPaths = {};
250
252
  Object.keys(document.paths).forEach((path) => {
package/dist/index.d.cts CHANGED
@@ -6,8 +6,8 @@ import { InfoStatusCode, SuccessStatusCode, RedirectStatusCode, ClientErrorStatu
6
6
  import { SimplifyDeepArray, JSONValue, JSONParsed, RemoveBlankRecord } from 'hono/utils/types';
7
7
  import { OpenAPIObject } from 'openapi3-ts/oas30';
8
8
  import { OpenAPIObject as OpenAPIObject$1 } from 'openapi3-ts/oas31';
9
- import { ZodType, z, ZodError } from 'zod/v4';
10
- export { z } from 'zod/v4';
9
+ import { ZodType, z, ZodError } from 'zod';
10
+ export { z } from 'zod';
11
11
 
12
12
  type MaybePromise<T> = Promise<T> | T;
13
13
  type RouteConfig = RouteConfig$1 & {
@@ -139,6 +139,8 @@ type RouteHandler<R extends RouteConfig, E extends Env = RouteConfigToEnv<R>, I
139
139
  type RouteHook<R extends RouteConfig, E extends Env = RouteConfigToEnv<R>, I extends Input = InputTypeParam<R> & InputTypeQuery<R> & InputTypeHeader<R> & InputTypeCookie<R> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R['path']>> = Hook<I, E, P, RouteConfigToTypedResponse<R> | Response | Promise<Response> | void | Promise<void>>;
140
140
  type OpenAPIObjectConfig = Parameters<InstanceType<typeof OpenApiGeneratorV3>['generateDocument']>[0];
141
141
  type OpenAPIObjectConfigure<E extends Env, P extends string> = OpenAPIObjectConfig | ((context: Context<E, P>) => OpenAPIObjectConfig);
142
+ type OpenAPIGeneratorOptions = ConstructorParameters<typeof OpenApiGeneratorV3>[1];
143
+ type OpenAPIGeneratorConfigure<E extends Env, P extends string> = OpenAPIGeneratorOptions | ((context: Context<E, P>) => OpenAPIGeneratorOptions);
142
144
  declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> extends Hono<E, S, BasePath> {
143
145
  openAPIRegistry: OpenAPIRegistry;
144
146
  defaultHook?: OpenAPIHonoOptions<E>['defaultHook'];
@@ -191,10 +193,10 @@ declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath e
191
193
  };
192
194
  };
193
195
  } ? MaybePromise<RouteConfigToTypedResponse<R>> | undefined : MaybePromise<RouteConfigToTypedResponse<R>> | MaybePromise<Response> | undefined> | undefined) => OpenAPIHono<E, S & ToSchema<R["method"], MergePath<BasePath, P>, I, RouteConfigToTypedResponse<R>>, BasePath>;
194
- getOpenAPIDocument: (config: OpenAPIObjectConfig) => OpenAPIObject;
195
- getOpenAPI31Document: (config: OpenAPIObjectConfig) => OpenAPIObject$1;
196
- doc: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
197
- doc31: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
196
+ getOpenAPIDocument: (objectConfig: OpenAPIObjectConfig, generatorConfig?: OpenAPIGeneratorOptions) => OpenAPIObject;
197
+ getOpenAPI31Document: (objectConfig: OpenAPIObjectConfig, generatorConfig?: OpenAPIGeneratorOptions) => OpenAPIObject$1;
198
+ doc: <P extends string>(path: P, configureObject: OpenAPIObjectConfigure<E, P>, configureGenerator?: OpenAPIGeneratorConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
199
+ doc31: <P extends string>(path: P, configureObject: OpenAPIObjectConfigure<E, P>, configureGenerator?: OpenAPIGeneratorConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
198
200
  route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string>(path: SubPath, app: Hono<SubEnv, SubSchema, SubBasePath>): OpenAPIHono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>;
199
201
  route<SubPath extends string>(path: SubPath): Hono<E, RemoveBlankRecord<S>, BasePath>;
200
202
  basePath<SubPath extends string>(path: SubPath): OpenAPIHono<E, S, MergePath<BasePath, SubPath>>;
@@ -206,4 +208,4 @@ declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"
206
208
  getRoutingPath(): RoutingPath<R["path"]>;
207
209
  };
208
210
 
209
- export { type DeepSimplify, type Hook, type MiddlewareToHandlerType, type OfHandlerType, OpenAPIHono, type OpenAPIHonoOptions, type OpenAPIObjectConfigure, type RouteConfig, type RouteConfigToEnv, type RouteConfigToTypedResponse, type RouteHandler, type RouteHook, createRoute };
211
+ export { type DeepSimplify, type Hook, type MiddlewareToHandlerType, type OfHandlerType, type OpenAPIGeneratorConfigure, type OpenAPIGeneratorOptions, OpenAPIHono, type OpenAPIHonoOptions, type OpenAPIObjectConfigure, type RouteConfig, type RouteConfigToEnv, type RouteConfigToTypedResponse, type RouteHandler, type RouteHook, createRoute };
package/dist/index.d.ts CHANGED
@@ -6,8 +6,8 @@ import { InfoStatusCode, SuccessStatusCode, RedirectStatusCode, ClientErrorStatu
6
6
  import { SimplifyDeepArray, JSONValue, JSONParsed, RemoveBlankRecord } from 'hono/utils/types';
7
7
  import { OpenAPIObject } from 'openapi3-ts/oas30';
8
8
  import { OpenAPIObject as OpenAPIObject$1 } from 'openapi3-ts/oas31';
9
- import { ZodType, z, ZodError } from 'zod/v4';
10
- export { z } from 'zod/v4';
9
+ import { ZodType, z, ZodError } from 'zod';
10
+ export { z } from 'zod';
11
11
 
12
12
  type MaybePromise<T> = Promise<T> | T;
13
13
  type RouteConfig = RouteConfig$1 & {
@@ -139,6 +139,8 @@ type RouteHandler<R extends RouteConfig, E extends Env = RouteConfigToEnv<R>, I
139
139
  type RouteHook<R extends RouteConfig, E extends Env = RouteConfigToEnv<R>, I extends Input = InputTypeParam<R> & InputTypeQuery<R> & InputTypeHeader<R> & InputTypeCookie<R> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R['path']>> = Hook<I, E, P, RouteConfigToTypedResponse<R> | Response | Promise<Response> | void | Promise<void>>;
140
140
  type OpenAPIObjectConfig = Parameters<InstanceType<typeof OpenApiGeneratorV3>['generateDocument']>[0];
141
141
  type OpenAPIObjectConfigure<E extends Env, P extends string> = OpenAPIObjectConfig | ((context: Context<E, P>) => OpenAPIObjectConfig);
142
+ type OpenAPIGeneratorOptions = ConstructorParameters<typeof OpenApiGeneratorV3>[1];
143
+ type OpenAPIGeneratorConfigure<E extends Env, P extends string> = OpenAPIGeneratorOptions | ((context: Context<E, P>) => OpenAPIGeneratorOptions);
142
144
  declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> extends Hono<E, S, BasePath> {
143
145
  openAPIRegistry: OpenAPIRegistry;
144
146
  defaultHook?: OpenAPIHonoOptions<E>['defaultHook'];
@@ -191,10 +193,10 @@ declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath e
191
193
  };
192
194
  };
193
195
  } ? MaybePromise<RouteConfigToTypedResponse<R>> | undefined : MaybePromise<RouteConfigToTypedResponse<R>> | MaybePromise<Response> | undefined> | undefined) => OpenAPIHono<E, S & ToSchema<R["method"], MergePath<BasePath, P>, I, RouteConfigToTypedResponse<R>>, BasePath>;
194
- getOpenAPIDocument: (config: OpenAPIObjectConfig) => OpenAPIObject;
195
- getOpenAPI31Document: (config: OpenAPIObjectConfig) => OpenAPIObject$1;
196
- doc: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
197
- doc31: <P extends string>(path: P, configure: OpenAPIObjectConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
196
+ getOpenAPIDocument: (objectConfig: OpenAPIObjectConfig, generatorConfig?: OpenAPIGeneratorOptions) => OpenAPIObject;
197
+ getOpenAPI31Document: (objectConfig: OpenAPIObjectConfig, generatorConfig?: OpenAPIGeneratorOptions) => OpenAPIObject$1;
198
+ doc: <P extends string>(path: P, configureObject: OpenAPIObjectConfigure<E, P>, configureGenerator?: OpenAPIGeneratorConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
199
+ doc31: <P extends string>(path: P, configureObject: OpenAPIObjectConfigure<E, P>, configureGenerator?: OpenAPIGeneratorConfigure<E, P>) => OpenAPIHono<E, S & ToSchema<"get", P, {}, {}>, BasePath>;
198
200
  route<SubPath extends string, SubEnv extends Env, SubSchema extends Schema, SubBasePath extends string>(path: SubPath, app: Hono<SubEnv, SubSchema, SubBasePath>): OpenAPIHono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>;
199
201
  route<SubPath extends string>(path: SubPath): Hono<E, RemoveBlankRecord<S>, BasePath>;
200
202
  basePath<SubPath extends string>(path: SubPath): OpenAPIHono<E, S, MergePath<BasePath, SubPath>>;
@@ -206,4 +208,4 @@ declare const createRoute: <P extends string, R extends Omit<RouteConfig, "path"
206
208
  getRoutingPath(): RoutingPath<R["path"]>;
207
209
  };
208
210
 
209
- export { type DeepSimplify, type Hook, type MiddlewareToHandlerType, type OfHandlerType, OpenAPIHono, type OpenAPIHonoOptions, type OpenAPIObjectConfigure, type RouteConfig, type RouteConfigToEnv, type RouteConfigToTypedResponse, type RouteHandler, type RouteHook, createRoute };
211
+ export { type DeepSimplify, type Hook, type MiddlewareToHandlerType, type OfHandlerType, type OpenAPIGeneratorConfigure, type OpenAPIGeneratorOptions, OpenAPIHono, type OpenAPIHonoOptions, type OpenAPIObjectConfigure, type RouteConfig, type RouteConfigToEnv, type RouteConfigToTypedResponse, type RouteHandler, type RouteHook, createRoute };
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  import { zValidator } from "@hono/zod-validator";
10
10
  import { Hono } from "hono";
11
11
  import { mergePath } from "hono/utils/url";
12
- import { ZodType, z } from "zod/v4";
12
+ import { ZodType, z } from "zod";
13
13
  var OpenAPIHono = class _OpenAPIHono extends Hono {
14
14
  openAPIRegistry;
15
15
  defaultHook;
@@ -126,32 +126,34 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
126
126
  );
127
127
  return this;
128
128
  };
129
- getOpenAPIDocument = (config) => {
130
- const generator = new OpenApiGeneratorV3(this.openAPIRegistry.definitions);
131
- const document = generator.generateDocument(config);
129
+ getOpenAPIDocument = (objectConfig, generatorConfig) => {
130
+ const generator = new OpenApiGeneratorV3(this.openAPIRegistry.definitions, generatorConfig);
131
+ const document = generator.generateDocument(objectConfig);
132
132
  return this._basePath ? addBasePathToDocument(document, this._basePath) : document;
133
133
  };
134
- getOpenAPI31Document = (config) => {
135
- const generator = new OpenApiGeneratorV31(this.openAPIRegistry.definitions);
136
- const document = generator.generateDocument(config);
134
+ getOpenAPI31Document = (objectConfig, generatorConfig) => {
135
+ const generator = new OpenApiGeneratorV31(this.openAPIRegistry.definitions, generatorConfig);
136
+ const document = generator.generateDocument(objectConfig);
137
137
  return this._basePath ? addBasePathToDocument(document, this._basePath) : document;
138
138
  };
139
- doc = (path, configure) => {
139
+ doc = (path, configureObject, configureGenerator) => {
140
140
  return this.get(path, (c) => {
141
- const config = typeof configure === "function" ? configure(c) : configure;
141
+ const objectConfig = typeof configureObject === "function" ? configureObject(c) : configureObject;
142
+ const generatorConfig = typeof configureGenerator === "function" ? configureGenerator(c) : configureGenerator;
142
143
  try {
143
- const document = this.getOpenAPIDocument(config);
144
+ const document = this.getOpenAPIDocument(objectConfig, generatorConfig);
144
145
  return c.json(document);
145
146
  } catch (e) {
146
147
  return c.json(e, 500);
147
148
  }
148
149
  });
149
150
  };
150
- doc31 = (path, configure) => {
151
+ doc31 = (path, configureObject, configureGenerator) => {
151
152
  return this.get(path, (c) => {
152
- const config = typeof configure === "function" ? configure(c) : configure;
153
+ const objectConfig = typeof configureObject === "function" ? configureObject(c) : configureObject;
154
+ const generatorConfig = typeof configureGenerator === "function" ? configureGenerator(c) : configureGenerator;
153
155
  try {
154
- const document = this.getOpenAPI31Document(config);
156
+ const document = this.getOpenAPI31Document(objectConfig, generatorConfig);
155
157
  return c.json(document);
156
158
  } catch (e) {
157
159
  return c.json(e, 500);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/zod-openapi",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "A wrapper class of Hono which supports OpenAPI.",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
@@ -54,7 +54,7 @@
54
54
  "zod": "^4.0.5"
55
55
  },
56
56
  "dependencies": {
57
- "@asteasolutions/zod-to-openapi": "^8.0.0",
57
+ "@asteasolutions/zod-to-openapi": "^8.1.0",
58
58
  "@hono/zod-validator": "^0.7.2",
59
59
  "openapi3-ts": "^4.5.0"
60
60
  },