(servers: readonly ServerObject[] | undefined)
| 515 | // --------------------------------------------------------------------------- |
| 516 | |
| 517 | const extractServerList = (servers: readonly ServerObject[] | undefined): ServerInfo[] => |
| 518 | (servers ?? []).flatMap((server) => { |
| 519 | if (!server.url) return []; |
| 520 | const serverVariables = server.variables as |
| 521 | | Record< |
| 522 | string, |
| 523 | { |
| 524 | readonly default?: string; |
| 525 | readonly enum?: readonly string[]; |
| 526 | readonly description?: string; |
| 527 | } |
| 528 | > |
| 529 | | undefined; |
| 530 | const vars = serverVariables |
| 531 | ? Object.fromEntries( |
| 532 | Object.entries(serverVariables).flatMap(([name, v]) => { |
| 533 | if (v.default === undefined || v.default === null) return []; |
| 534 | const enumValues = Array.isArray(v.enum) |
| 535 | ? v.enum.filter((x): x is string => typeof x === "string") |
| 536 | : undefined; |
| 537 | return [ |
| 538 | [ |
| 539 | name, |
| 540 | ServerVariable.make({ |
| 541 | default: String(v.default), |
| 542 | enum: |
| 543 | enumValues && enumValues.length > 0 ? Option.some(enumValues) : Option.none(), |
| 544 | description: Option.fromNullishOr(v.description), |
| 545 | }), |
| 546 | ], |
| 547 | ]; |
| 548 | }), |
| 549 | ) |
| 550 | : undefined; |
| 551 | return [ |
| 552 | ServerInfo.make({ |
| 553 | url: server.url, |
| 554 | description: Option.fromNullishOr(server.description), |
| 555 | variables: vars && Object.keys(vars).length > 0 ? Option.some(vars) : Option.none(), |
| 556 | }), |
| 557 | ]; |
| 558 | }); |
| 559 | |
| 560 | const extractServers = (doc: ParsedDocument): ServerInfo[] => extractServerList(doc.servers); |
| 561 |
no outgoing calls
no test coverage detected