( servers: readonly ServerInfo[], serverArg: unknown, baseUrl: string, )
| 1375 | // Connection `baseUrl` wins; otherwise the call's chosen server (`server.url`, or |
| 1376 | // the first) resolved with its `{variables}` (call values, else spec defaults). |
| 1377 | const resolveRequestHost = ( |
| 1378 | servers: readonly ServerInfo[], |
| 1379 | serverArg: unknown, |
| 1380 | baseUrl: string, |
| 1381 | ): string => { |
| 1382 | if (baseUrl) return baseUrl; |
| 1383 | if (servers.length === 0) return ""; |
| 1384 | |
| 1385 | const arg = ( |
| 1386 | typeof serverArg === "object" && serverArg !== null && !Array.isArray(serverArg) |
| 1387 | ? serverArg |
| 1388 | : {} |
| 1389 | ) as { url?: unknown; variables?: unknown }; |
| 1390 | const chosen = servers.find((server) => server.url === arg.url) ?? servers[0]!; |
| 1391 | |
| 1392 | const overrides: Record<string, string> = {}; |
| 1393 | if (typeof arg.variables === "object" && arg.variables !== null) { |
| 1394 | for (const [name, value] of Object.entries(arg.variables as Record<string, unknown>)) { |
| 1395 | if (value != null && value !== "") overrides[name] = String(value); |
| 1396 | } |
| 1397 | } |
| 1398 | return resolveServerUrl(chosen.url, Option.getOrUndefined(chosen.variables), overrides); |
| 1399 | }; |
| 1400 | |
| 1401 | const baseUrlForPathTemplate = (baseUrl: string, pathTemplate: string): string => { |
| 1402 | if (!baseUrl || !pathTemplate.startsWith("/upload/") || !URL.canParse(baseUrl)) return baseUrl; |
no test coverage detected