| 707 | const paramsRegExp = /(\/?):(\w+)(\?)?/g |
| 708 | |
| 709 | const compilePath = (path: string) => { |
| 710 | if (!paramsRegExp.test(path)) { |
| 711 | return (_: any) => path |
| 712 | } |
| 713 | paramsRegExp.lastIndex = 0 |
| 714 | return (params: Record<string, string | undefined>) => { |
| 715 | paramsRegExp.lastIndex = 0 |
| 716 | return path.replace(paramsRegExp, (_, slash: string, key: string, optional: string | undefined) => { |
| 717 | const value = params[key] |
| 718 | if (value === undefined) { |
| 719 | if (optional !== undefined) { |
| 720 | return "" |
| 721 | } |
| 722 | throw new Error(`Missing path parameter: ${key}`) |
| 723 | } |
| 724 | return `${slash}${encodeURIComponent(value)}` |
| 725 | }) |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | function schemasToResponse(schemas: readonly [Schema.Constraint, ...Array<Schema.Constraint>]) { |
| 730 | const hasWithHeaders = schemas.some((schema) => |