fix(zod-openapi): make getRoutingPath non-enumerable (#445)
* zod-openapi: make getRoutingPath non-enumerable This prevents potential serialisation errors (e.g. yaml's `stringify`) of the return value of getOpenAPIDocument * .changeset: add an entry for #445pull/446/head
parent
b865bb7ca4
commit
110e272460
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@hono/zod-openapi': patch
|
||||
---
|
||||
|
||||
Make getRoutingPath property of a RouteConfig non-enumerable
|
|
@ -431,12 +431,13 @@ type RoutingPath<P extends string> = P extends `${infer Head}/{${infer Param}}${
|
|||
export const createRoute = <P extends string, R extends Omit<RouteConfig, 'path'> & { path: P }>(
|
||||
routeConfig: R
|
||||
) => {
|
||||
return {
|
||||
const route = {
|
||||
...routeConfig,
|
||||
getRoutingPath(): RoutingPath<R['path']> {
|
||||
return routeConfig.path.replaceAll(/\/{(.+?)}/g, '/:$1') as RoutingPath<P>
|
||||
},
|
||||
}
|
||||
return Object.defineProperty(route, 'getRoutingPath', { enumerable: false })
|
||||
}
|
||||
|
||||
extendZodWithOpenApi(z)
|
||||
|
|
|
@ -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<typeof expected>()
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue