( root: UnknownRecord, operation: UnknownRecord, source: string, warnings: HttpImportWarning[], )
| 378 | } |
| 379 | |
| 380 | function parseSecurity( |
| 381 | root: UnknownRecord, |
| 382 | operation: UnknownRecord, |
| 383 | source: string, |
| 384 | warnings: HttpImportWarning[], |
| 385 | ): { |
| 386 | auth: HttpAuth |
| 387 | headers: HttpHeaderEntry[] |
| 388 | query: HttpQueryEntry[] |
| 389 | variables: Record<string, string> |
| 390 | } { |
| 391 | const requirements = Array.isArray(operation.security) |
| 392 | ? operation.security |
| 393 | : asArray(root.security) |
| 394 | const requirement = requirements.find(isRecord) |
| 395 | if (!requirement) |
| 396 | return { auth: { type: 'none' }, headers: [], query: [], variables: {} } |
| 397 | |
| 398 | const schemes = getSecuritySchemes(root) |
| 399 | const variables: Record<string, string> = {} |
| 400 | |
| 401 | for (const name of Object.keys(requirement)) { |
| 402 | const scheme = schemes[name] |
| 403 | if (!isRecord(scheme)) |
| 404 | continue |
| 405 | |
| 406 | if ( |
| 407 | scheme.type === 'http' |
| 408 | && asString(scheme.scheme).toLowerCase() === 'bearer' |
| 409 | ) { |
| 410 | variables[name] = '' |
| 411 | return { |
| 412 | auth: { token: `{{${name}}}`, type: 'bearer' }, |
| 413 | headers: [], |
| 414 | query: [], |
| 415 | variables, |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | if ( |
| 420 | scheme.type === 'http' |
| 421 | && asString(scheme.scheme).toLowerCase() === 'basic' |
| 422 | ) { |
| 423 | variables[`${name}Username`] = '' |
| 424 | variables[`${name}Password`] = '' |
| 425 | return { |
| 426 | auth: { |
| 427 | password: `{{${name}Password}}`, |
| 428 | type: 'basic', |
| 429 | username: `{{${name}Username}}`, |
| 430 | }, |
| 431 | headers: [], |
| 432 | query: [], |
| 433 | variables, |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | if (scheme.type === 'apiKey') { |
no test coverage detected