| 404 | // --------------------------------------------------------------------------- |
| 405 | |
| 406 | const buildOAuth2Presets = (schemes: readonly SecurityScheme[]): OAuth2Preset[] => { |
| 407 | const presets: OAuth2Preset[] = []; |
| 408 | for (const scheme of schemes) { |
| 409 | if (scheme.type !== "oauth2") continue; |
| 410 | if (Option.isNone(scheme.flows)) continue; |
| 411 | const flows = scheme.flows.value; |
| 412 | |
| 413 | if (Option.isSome(flows.authorizationCode)) { |
| 414 | const flow = flows.authorizationCode.value; |
| 415 | presets.push( |
| 416 | OAuth2Preset.make({ |
| 417 | label: `OAuth2 Authorization Code · ${scheme.name}`, |
| 418 | securitySchemeName: scheme.name, |
| 419 | flow: "authorizationCode", |
| 420 | authorizationUrl: Option.some(flow.authorizationUrl), |
| 421 | tokenUrl: flow.tokenUrl, |
| 422 | resource: Option.none(), |
| 423 | refreshUrl: flow.refreshUrl, |
| 424 | scopes: flow.scopes, |
| 425 | identityScopes: "auto", |
| 426 | }), |
| 427 | ); |
| 428 | } |
| 429 | |
| 430 | if (Option.isSome(flows.clientCredentials)) { |
| 431 | const flow = flows.clientCredentials.value; |
| 432 | presets.push( |
| 433 | OAuth2Preset.make({ |
| 434 | label: `OAuth2 Client Credentials · ${scheme.name}`, |
| 435 | securitySchemeName: scheme.name, |
| 436 | flow: "clientCredentials", |
| 437 | authorizationUrl: Option.none(), |
| 438 | tokenUrl: flow.tokenUrl, |
| 439 | resource: Option.none(), |
| 440 | refreshUrl: flow.refreshUrl, |
| 441 | scopes: flow.scopes, |
| 442 | identityScopes: false, |
| 443 | }), |
| 444 | ); |
| 445 | } |
| 446 | } |
| 447 | return presets; |
| 448 | }; |
| 449 | |
| 450 | // --------------------------------------------------------------------------- |
| 451 | // Collect unique tags from extraction result |