(servers: readonly ServerObject[] | undefined)
| 439 | // --------------------------------------------------------------------------- |
| 440 | |
| 441 | const extractServerList = (servers: readonly ServerObject[] | undefined): ServerInfo[] => |
| 442 | (servers ?? []).flatMap((server) => { |
| 443 | if (!server.url) return []; |
| 444 | const serverVariables = server.variables as |
| 445 | | Record< |
| 446 | string, |
| 447 | { |
| 448 | readonly default?: string; |
| 449 | readonly enum?: readonly string[]; |
| 450 | readonly description?: string; |
| 451 | } |
| 452 | > |
| 453 | | undefined; |
| 454 | const vars = serverVariables |
| 455 | ? Object.fromEntries( |
| 456 | Object.entries(serverVariables).flatMap(([name, v]) => { |
| 457 | if (v.default === undefined || v.default === null) return []; |
| 458 | const enumValues = Array.isArray(v.enum) |
| 459 | ? v.enum.filter((x): x is string => typeof x === "string") |
| 460 | : undefined; |
| 461 | return [ |
| 462 | [ |
| 463 | name, |
| 464 | ServerVariable.make({ |
| 465 | default: String(v.default), |
| 466 | enum: |
| 467 | enumValues && enumValues.length > 0 ? Option.some(enumValues) : Option.none(), |
| 468 | description: Option.fromNullishOr(v.description), |
| 469 | }), |
| 470 | ], |
| 471 | ]; |
| 472 | }), |
| 473 | ) |
| 474 | : undefined; |
| 475 | return [ |
| 476 | ServerInfo.make({ |
| 477 | url: server.url, |
| 478 | description: Option.fromNullishOr(server.description), |
| 479 | variables: vars && Object.keys(vars).length > 0 ? Option.some(vars) : Option.none(), |
| 480 | }), |
| 481 | ]; |
| 482 | }); |
| 483 | |
| 484 | const extractServers = (doc: ParsedDocument): ServerInfo[] => extractServerList(doc.servers); |
| 485 |
no outgoing calls
no test coverage detected