(router: T, options: PopulateContractRouterPathsOptions = {})
| 124 | * @see {@link https://orpc.dev/docs/openapi/integrations/implement-contract-in-nest#define-your-contract NestJS Implement Contract Docs} |
| 125 | */ |
| 126 | export function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options: PopulateContractRouterPathsOptions = {}): PopulatedContractRouterPaths<T> { |
| 127 | const path = toArray(options.path) |
| 128 | |
| 129 | if (isContractProcedure(router)) { |
| 130 | if (router['~orpc'].route.path === undefined) { |
| 131 | return new ContractProcedure({ |
| 132 | ...router['~orpc'], |
| 133 | route: { |
| 134 | ...router['~orpc'].route, |
| 135 | path: toHttpPath(path), |
| 136 | }, |
| 137 | }) as any |
| 138 | } |
| 139 | |
| 140 | return router as any |
| 141 | } |
| 142 | |
| 143 | if (typeof router !== 'object' || router === null) { |
| 144 | return router as any |
| 145 | } |
| 146 | |
| 147 | const populated: Record<string, any> = {} |
| 148 | |
| 149 | for (const key in router) { |
| 150 | populated[key] = populateContractRouterPaths(router[key]!, { ...options, path: [...path, key] }) |
| 151 | } |
| 152 | |
| 153 | return populated as any |
| 154 | } |
no test coverage detected