(args: {
securityRequirement: OpenAPIV3.OperationObject['security'];
securities: OpenAPIOperationData['securities'];
})
| 291 | } |
| 292 | |
| 293 | function getSecurityHeaders(args: { |
| 294 | securityRequirement: OpenAPIV3.OperationObject['security']; |
| 295 | securities: OpenAPIOperationData['securities']; |
| 296 | }): { |
| 297 | [key: string]: string; |
| 298 | } { |
| 299 | const { securityRequirement, securities } = args; |
| 300 | const operationSecurityInfo = extractOperationSecurityInfo({ securityRequirement, securities }); |
| 301 | |
| 302 | if (operationSecurityInfo.length === 0) { |
| 303 | return {}; |
| 304 | } |
| 305 | |
| 306 | const selectedSecurity = operationSecurityInfo.at(0); |
| 307 | |
| 308 | if (!selectedSecurity) { |
| 309 | return {}; |
| 310 | } |
| 311 | |
| 312 | const headers: { [key: string]: string } = {}; |
| 313 | |
| 314 | for (const security of selectedSecurity.schemes) { |
| 315 | switch (security.type) { |
| 316 | case 'http': { |
| 317 | let scheme = security.scheme; |
| 318 | const format = resolvePrefillCodePlaceholderFromSecurityScheme({ |
| 319 | security: security, |
| 320 | defaultPlaceholderValue: scheme?.includes('basic') |
| 321 | ? 'username:password' |
| 322 | : 'YOUR_SECRET_TOKEN', |
| 323 | }); |
| 324 | |
| 325 | if (scheme?.includes('bearer')) { |
| 326 | scheme = 'Bearer'; |
| 327 | } else if (scheme?.includes('basic')) { |
| 328 | scheme = 'Basic'; |
| 329 | } else if (scheme?.includes('token')) { |
| 330 | scheme = 'Token'; |
| 331 | } |
| 332 | |
| 333 | headers.Authorization = `${scheme} ${format}`; |
| 334 | break; |
| 335 | } |
| 336 | case 'apiKey': { |
| 337 | if (security.in !== 'header') { |
| 338 | break; |
| 339 | } |
| 340 | const name = security.name ?? 'Authorization'; |
| 341 | headers[name] = resolvePrefillCodePlaceholderFromSecurityScheme({ |
| 342 | security: security, |
| 343 | defaultPlaceholderValue: 'YOUR_API_KEY', |
| 344 | }); |
| 345 | break; |
| 346 | } |
| 347 | case 'oauth2': { |
| 348 | headers.Authorization = `Bearer ${resolvePrefillCodePlaceholderFromSecurityScheme({ |
| 349 | security: security, |
| 350 | defaultPlaceholderValue: 'YOUR_OAUTH2_TOKEN', |
no test coverage detected