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 }>(
|
export const createRoute = <P extends string, R extends Omit<RouteConfig, 'path'> & { path: P }>(
|
||||||
routeConfig: R
|
routeConfig: R
|
||||||
) => {
|
) => {
|
||||||
return {
|
const route = {
|
||||||
...routeConfig,
|
...routeConfig,
|
||||||
getRoutingPath(): RoutingPath<R['path']> {
|
getRoutingPath(): RoutingPath<R['path']> {
|
||||||
return routeConfig.path.replaceAll(/\/{(.+?)}/g, '/:$1') as RoutingPath<P>
|
return routeConfig.path.replaceAll(/\/{(.+?)}/g, '/:$1') as RoutingPath<P>
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
return Object.defineProperty(route, 'getRoutingPath', { enumerable: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
extendZodWithOpenApi(z)
|
extendZodWithOpenApi(z)
|
||||||
|
|
|
@ -50,11 +50,7 @@ describe('createRoute', () => {
|
||||||
},
|
},
|
||||||
} as const
|
} as const
|
||||||
const route = createRoute(config)
|
const route = createRoute(config)
|
||||||
|
expect(route).toEqual(config)
|
||||||
expect(route).toEqual({
|
|
||||||
...config,
|
|
||||||
getRoutingPath: expect.any(Function),
|
|
||||||
})
|
|
||||||
expect(route.getRoutingPath()).toBe(expected)
|
expect(route.getRoutingPath()).toBe(expected)
|
||||||
expectTypeOf(route.getRoutingPath()).toEqualTypeOf<typeof expected>()
|
expectTypeOf(route.getRoutingPath()).toEqualTypeOf<typeof expected>()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue