| 385 | // --------------------------------------------------------------------------- |
| 386 | |
| 387 | const buildOAuth2Presets = (schemes: readonly SecurityScheme[]): OAuth2Preset[] => { |
| 388 | const presets: OAuth2Preset[] = []; |
| 389 | for (const scheme of schemes) { |
| 390 | if (scheme.type !== "oauth2") continue; |
| 391 | if (Option.isNone(scheme.flows)) continue; |
| 392 | const flows = scheme.flows.value; |
| 393 | |
| 394 | if (Option.isSome(flows.authorizationCode)) { |
| 395 | const flow = flows.authorizationCode.value; |
| 396 | presets.push( |
| 397 | OAuth2Preset.make({ |
| 398 | label: `OAuth2 Authorization Code · ${scheme.name}`, |
| 399 | securitySchemeName: scheme.name, |
| 400 | flow: "authorizationCode", |
| 401 | authorizationUrl: Option.some(flow.authorizationUrl), |
| 402 | tokenUrl: flow.tokenUrl, |
| 403 | resource: Option.none(), |
| 404 | refreshUrl: flow.refreshUrl, |
| 405 | scopes: flow.scopes, |
| 406 | identityScopes: "auto", |
| 407 | }), |
| 408 | ); |
| 409 | } |
| 410 | |
| 411 | if (Option.isSome(flows.clientCredentials)) { |
| 412 | const flow = flows.clientCredentials.value; |
| 413 | presets.push( |
| 414 | OAuth2Preset.make({ |
| 415 | label: `OAuth2 Client Credentials · ${scheme.name}`, |
| 416 | securitySchemeName: scheme.name, |
| 417 | flow: "clientCredentials", |
| 418 | authorizationUrl: Option.none(), |
| 419 | tokenUrl: flow.tokenUrl, |
| 420 | resource: Option.none(), |
| 421 | refreshUrl: flow.refreshUrl, |
| 422 | scopes: flow.scopes, |
| 423 | identityScopes: false, |
| 424 | }), |
| 425 | ); |
| 426 | } |
| 427 | } |
| 428 | return presets; |
| 429 | }; |
| 430 | |
| 431 | // --------------------------------------------------------------------------- |
| 432 | // Collect unique tags from extraction result |