diff --git a/.changeset/long-crabs-drum.md b/.changeset/long-crabs-drum.md new file mode 100644 index 00000000..95ba8622 --- /dev/null +++ b/.changeset/long-crabs-drum.md @@ -0,0 +1,5 @@ +--- +'@hono/zod-openapi': patch +--- + +Make getRoutingPath property of a RouteConfig non-enumerable diff --git a/packages/zod-openapi/src/index.ts b/packages/zod-openapi/src/index.ts index 887fafcf..bb62a6f5 100644 --- a/packages/zod-openapi/src/index.ts +++ b/packages/zod-openapi/src/index.ts @@ -431,12 +431,13 @@ type RoutingPath

= P extends `${infer Head}/{${infer Param}}${ export const createRoute =

& { path: P }>( routeConfig: R ) => { - return { + const route = { ...routeConfig, getRoutingPath(): RoutingPath { return routeConfig.path.replaceAll(/\/{(.+?)}/g, '/:$1') as RoutingPath

}, } + return Object.defineProperty(route, 'getRoutingPath', { enumerable: false }) } extendZodWithOpenApi(z) diff --git a/packages/zod-openapi/test/createRoute.test.ts b/packages/zod-openapi/test/createRoute.test.ts index 52e59635..a0445232 100644 --- a/packages/zod-openapi/test/createRoute.test.ts +++ b/packages/zod-openapi/test/createRoute.test.ts @@ -50,11 +50,7 @@ describe('createRoute', () => { }, } as const const route = createRoute(config) - - expect(route).toEqual({ - ...config, - getRoutingPath: expect.any(Function), - }) + expect(route).toEqual(config) expect(route.getRoutingPath()).toBe(expected) expectTypeOf(route.getRoutingPath()).toEqualTypeOf() })