@hono/zod-openapi 0.18.4 → 0.19.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/README.md +11 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -3
- package/dist/index.mjs +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -451,6 +451,17 @@ app.doc('/doc', (c) => ({
|
|
|
451
451
|
}))
|
|
452
452
|
```
|
|
453
453
|
|
|
454
|
+
### How to exclude a specific route from OpenAPI docs
|
|
455
|
+
|
|
456
|
+
You can use `hide` property as follows:
|
|
457
|
+
|
|
458
|
+
```ts
|
|
459
|
+
const route = createRoute({
|
|
460
|
+
// ...
|
|
461
|
+
hide: true,
|
|
462
|
+
})
|
|
463
|
+
```
|
|
464
|
+
|
|
454
465
|
## Limitations
|
|
455
466
|
|
|
456
467
|
### Combining with `Hono`
|
package/dist/index.d.mts
CHANGED
|
@@ -12,6 +12,7 @@ export { z } from 'zod';
|
|
|
12
12
|
type MaybePromise<T> = Promise<T> | T;
|
|
13
13
|
type RouteConfig = RouteConfig$1 & {
|
|
14
14
|
middleware?: MiddlewareHandler | MiddlewareHandler[];
|
|
15
|
+
hide?: boolean;
|
|
15
16
|
};
|
|
16
17
|
type RequestTypes = {
|
|
17
18
|
body?: ZodRequestBody;
|
|
@@ -169,7 +170,7 @@ declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath e
|
|
|
169
170
|
* }
|
|
170
171
|
*)
|
|
171
172
|
*/
|
|
172
|
-
openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>({ middleware: routeMiddleware, ...route }: R, handler: Handler<R['middleware'] extends MiddlewareHandler[] | MiddlewareHandler ? RouteMiddlewareParams<R>['env'] & E : E, P, I, R extends {
|
|
173
|
+
openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>({ middleware: routeMiddleware, hide, ...route }: R, handler: Handler<R['middleware'] extends MiddlewareHandler[] | MiddlewareHandler ? RouteMiddlewareParams<R>['env'] & E : E, P, I, R extends {
|
|
173
174
|
responses: {
|
|
174
175
|
[statusCode: number]: {
|
|
175
176
|
content: {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { z } from 'zod';
|
|
|
12
12
|
type MaybePromise<T> = Promise<T> | T;
|
|
13
13
|
type RouteConfig = RouteConfig$1 & {
|
|
14
14
|
middleware?: MiddlewareHandler | MiddlewareHandler[];
|
|
15
|
+
hide?: boolean;
|
|
15
16
|
};
|
|
16
17
|
type RequestTypes = {
|
|
17
18
|
body?: ZodRequestBody;
|
|
@@ -169,7 +170,7 @@ declare class OpenAPIHono<E extends Env = Env, S extends Schema = {}, BasePath e
|
|
|
169
170
|
* }
|
|
170
171
|
*)
|
|
171
172
|
*/
|
|
172
|
-
openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>({ middleware: routeMiddleware, ...route }: R, handler: Handler<R['middleware'] extends MiddlewareHandler[] | MiddlewareHandler ? RouteMiddlewareParams<R>['env'] & E : E, P, I, R extends {
|
|
173
|
+
openapi: <R extends RouteConfig, I extends Input = InputTypeBase<R, "params", "param"> & InputTypeBase<R, "query", "query"> & InputTypeBase<R, "headers", "header"> & InputTypeBase<R, "cookies", "cookie"> & InputTypeForm<R> & InputTypeJson<R>, P extends string = ConvertPathType<R["path"]>>({ middleware: routeMiddleware, hide, ...route }: R, handler: Handler<R['middleware'] extends MiddlewareHandler[] | MiddlewareHandler ? RouteMiddlewareParams<R>['env'] & E : E, P, I, R extends {
|
|
173
174
|
responses: {
|
|
174
175
|
[statusCode: number]: {
|
|
175
176
|
content: {
|
package/dist/index.js
CHANGED
|
@@ -70,8 +70,10 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
|
|
|
70
70
|
* }
|
|
71
71
|
*)
|
|
72
72
|
*/
|
|
73
|
-
openapi = ({ middleware: routeMiddleware, ...route }, handler, hook = this.defaultHook) => {
|
|
74
|
-
|
|
73
|
+
openapi = ({ middleware: routeMiddleware, hide, ...route }, handler, hook = this.defaultHook) => {
|
|
74
|
+
if (!hide) {
|
|
75
|
+
this.openAPIRegistry.registerPath(route);
|
|
76
|
+
}
|
|
75
77
|
const validators = [];
|
|
76
78
|
if (route.request?.query) {
|
|
77
79
|
const validator = (0, import_zod_validator.zValidator)("query", route.request.query, hook);
|
|
@@ -239,7 +241,7 @@ var createRoute = (routeConfig) => {
|
|
|
239
241
|
function addBasePathToDocument(document, basePath) {
|
|
240
242
|
const updatedPaths = {};
|
|
241
243
|
Object.keys(document.paths).forEach((path) => {
|
|
242
|
-
updatedPaths[(0, import_url.mergePath)(basePath, path)] = document.paths[path];
|
|
244
|
+
updatedPaths[(0, import_url.mergePath)(basePath.replaceAll(/:([^\/]+)/g, "{$1}"), path)] = document.paths[path];
|
|
243
245
|
});
|
|
244
246
|
return {
|
|
245
247
|
...document,
|
package/dist/index.mjs
CHANGED
|
@@ -48,8 +48,10 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
|
|
|
48
48
|
* }
|
|
49
49
|
*)
|
|
50
50
|
*/
|
|
51
|
-
openapi = ({ middleware: routeMiddleware, ...route }, handler, hook = this.defaultHook) => {
|
|
52
|
-
|
|
51
|
+
openapi = ({ middleware: routeMiddleware, hide, ...route }, handler, hook = this.defaultHook) => {
|
|
52
|
+
if (!hide) {
|
|
53
|
+
this.openAPIRegistry.registerPath(route);
|
|
54
|
+
}
|
|
53
55
|
const validators = [];
|
|
54
56
|
if (route.request?.query) {
|
|
55
57
|
const validator = zValidator("query", route.request.query, hook);
|
|
@@ -217,7 +219,7 @@ extendZodWithOpenApi(z);
|
|
|
217
219
|
function addBasePathToDocument(document, basePath) {
|
|
218
220
|
const updatedPaths = {};
|
|
219
221
|
Object.keys(document.paths).forEach((path) => {
|
|
220
|
-
updatedPaths[mergePath(basePath, path)] = document.paths[path];
|
|
222
|
+
updatedPaths[mergePath(basePath.replaceAll(/:([^\/]+)/g, "{$1}"), path)] = document.paths[path];
|
|
221
223
|
});
|
|
222
224
|
return {
|
|
223
225
|
...document,
|