@hono/zod-openapi 1.0.2 → 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 +6 -0
- package/README.md +11 -4
- package/dist/index.cjs +14 -12
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +14 -12
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 1.0.2
|
|
4
10
|
|
|
5
11
|
### 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
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
@@ -147,32 +147,34 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
|
|
|
147
147
|
);
|
|
148
148
|
return this;
|
|
149
149
|
};
|
|
150
|
-
getOpenAPIDocument = (
|
|
151
|
-
const generator = new import_zod_to_openapi.OpenApiGeneratorV3(this.openAPIRegistry.definitions);
|
|
152
|
-
const document = generator.generateDocument(
|
|
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 = (
|
|
156
|
-
const generator = new import_zod_to_openapi.OpenApiGeneratorV31(this.openAPIRegistry.definitions);
|
|
157
|
-
const document = generator.generateDocument(
|
|
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,
|
|
160
|
+
doc = (path, configureObject, configureGenerator) => {
|
|
161
161
|
return this.get(path, (c) => {
|
|
162
|
-
const
|
|
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(
|
|
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,
|
|
172
|
+
doc31 = (path, configureObject, configureGenerator) => {
|
|
172
173
|
return this.get(path, (c) => {
|
|
173
|
-
const
|
|
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(
|
|
177
|
+
const document = this.getOpenAPI31Document(objectConfig, generatorConfig);
|
|
176
178
|
return c.json(document);
|
|
177
179
|
} catch (e) {
|
|
178
180
|
return c.json(e, 500);
|
package/dist/index.d.cts
CHANGED
|
@@ -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: (
|
|
195
|
-
getOpenAPI31Document: (
|
|
196
|
-
doc: <P extends string>(path: P,
|
|
197
|
-
doc31: <P extends string>(path: P,
|
|
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
|
@@ -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: (
|
|
195
|
-
getOpenAPI31Document: (
|
|
196
|
-
doc: <P extends string>(path: P,
|
|
197
|
-
doc31: <P extends string>(path: P,
|
|
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
|
@@ -126,32 +126,34 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
|
|
|
126
126
|
);
|
|
127
127
|
return this;
|
|
128
128
|
};
|
|
129
|
-
getOpenAPIDocument = (
|
|
130
|
-
const generator = new OpenApiGeneratorV3(this.openAPIRegistry.definitions);
|
|
131
|
-
const document = generator.generateDocument(
|
|
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 = (
|
|
135
|
-
const generator = new OpenApiGeneratorV31(this.openAPIRegistry.definitions);
|
|
136
|
-
const document = generator.generateDocument(
|
|
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,
|
|
139
|
+
doc = (path, configureObject, configureGenerator) => {
|
|
140
140
|
return this.get(path, (c) => {
|
|
141
|
-
const
|
|
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(
|
|
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,
|
|
151
|
+
doc31 = (path, configureObject, configureGenerator) => {
|
|
151
152
|
return this.get(path, (c) => {
|
|
152
|
-
const
|
|
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(
|
|
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
|
|
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.
|
|
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
|
},
|