( servers: readonly ServerInfo[], serverArg: unknown, baseUrl: string, )
| 1269 | // Connection `baseUrl` wins; otherwise the call's chosen server (`server.url`, or |
| 1270 | // the first) resolved with its `{variables}` (call values, else spec defaults). |
| 1271 | const resolveRequestHost = ( |
| 1272 | servers: readonly ServerInfo[], |
| 1273 | serverArg: unknown, |
| 1274 | baseUrl: string, |
| 1275 | ): string => { |
| 1276 | if (baseUrl) return baseUrl; |
| 1277 | if (servers.length === 0) return ""; |
| 1278 | |
| 1279 | const arg = ( |
| 1280 | typeof serverArg === "object" && serverArg !== null && !Array.isArray(serverArg) |
| 1281 | ? serverArg |
| 1282 | : {} |
| 1283 | ) as { url?: unknown; variables?: unknown }; |
| 1284 | const chosen = servers.find((server) => server.url === arg.url) ?? servers[0]!; |
| 1285 | |
| 1286 | const overrides: Record<string, string> = {}; |
| 1287 | if (typeof arg.variables === "object" && arg.variables !== null) { |
| 1288 | for (const [name, value] of Object.entries(arg.variables as Record<string, unknown>)) { |
| 1289 | if (value != null && value !== "") overrides[name] = String(value); |
| 1290 | } |
| 1291 | } |
| 1292 | return resolveServerUrl(chosen.url, Option.getOrUndefined(chosen.variables), overrides); |
| 1293 | }; |
| 1294 | |
| 1295 | const baseUrlForPathTemplate = (baseUrl: string, pathTemplate: string): string => { |
| 1296 | if (!baseUrl || !pathTemplate.startsWith("/upload/") || !URL.canParse(baseUrl)) return baseUrl; |
no test coverage detected