1
+ /* eslint-disable arrow-body-style */
1
2
import { html } from 'lit-element' ;
2
3
import { unsafeHTML } from 'lit-html/directives/unsafe-html' ;
3
4
import marked from 'marked' ;
@@ -449,19 +450,18 @@ export function pathSecurityTemplate(pathSecurity) {
449
450
pathSecurity . forEach ( ( pSecurity ) => {
450
451
const andSecurityKeys1 = [ ] ;
451
452
const andKeyTypes = [ ] ;
452
- let pathScopes = '' ;
453
453
Object . keys ( pSecurity ) . forEach ( ( pathSecurityKey ) => {
454
+ let pathScopes = '' ;
454
455
const s = this . resolvedSpec . securitySchemes . find ( ( ss ) => ss . securitySchemeId === pathSecurityKey ) ;
455
- if ( ! pathScopes && Array . isArray ( pSecurity [ pathSecurityKey ] ) ) {
456
+ if ( pSecurity [ pathSecurityKey ] && Array . isArray ( pSecurity [ pathSecurityKey ] ) ) {
456
457
pathScopes = pSecurity [ pathSecurityKey ] . join ( ', ' ) ;
457
458
}
458
459
if ( s ) {
459
460
andKeyTypes . push ( s . typeDisplay ) ;
460
- andSecurityKeys1 . push ( s ) ;
461
+ andSecurityKeys1 . push ( { ... s , ... ( { scopes : pathScopes } ) } ) ;
461
462
}
462
463
} ) ;
463
464
orSecurityKeys1 . push ( {
464
- pathScopes,
465
465
securityTypes : andKeyTypes . length > 1 ? `${ andKeyTypes [ 0 ] } + ${ andKeyTypes . length - 1 } more` : andKeyTypes [ 0 ] ,
466
466
securityDefs : andSecurityKeys1 ,
467
467
} ) ;
@@ -485,7 +485,20 @@ export function pathSecurityTemplate(pathSecurity) {
485
485
< div class ="tooltip-text " style ="position:absolute; color: var(--fg); top:26px; right:0; border:1px solid var(--border-color);padding:2px 4px; display:block; ">
486
486
${ orSecurityItem1 . securityDefs . length > 1 ? html `< div > Requires < b > all</ b > of the following </ div > ` : '' }
487
487
< div style ="padding-left: 8px ">
488
- ${ orSecurityItem1 . securityDefs . map ( ( andSecurityItem , j ) => html `
488
+ ${ orSecurityItem1 . securityDefs . map ( ( andSecurityItem , j ) => {
489
+ const scopeHtml = html `${ andSecurityItem . scopes !== ''
490
+ ? html `
491
+ < div >
492
+ < b > Required scopes:</ b >
493
+ < br />
494
+ < div style ="margin-left:8px ">
495
+ ${ andSecurityItem . scopes . split ( ',' ) . map ( ( scope , cnt ) => html `${ cnt === 0 ? '' : '┃' } < span > ${ scope } </ span > ` ) }
496
+ </ div >
497
+ </ div > `
498
+ : ''
499
+ } `;
500
+
501
+ return html `
489
502
${ andSecurityItem . type === 'oauth2'
490
503
? html `
491
504
< div >
@@ -494,31 +507,23 @@ export function pathSecurityTemplate(pathSecurity) {
494
507
: 'Needs'
495
508
}
496
509
OAuth Token < span style ="font-family:var(--font-mono); color:var(--primary-color); "> ${ andSecurityItem . securitySchemeId } </ span > in < b > Authorization header</ b >
497
- ${ orSecurityItem1 . pathScopes !== ''
498
- ? html `
499
- < div >
500
- < b > Required scopes:</ b >
501
- < br />
502
- < div style ="margin-left:8px ">
503
- ${ orSecurityItem1 . pathScopes . split ( ',' ) . map ( ( scope , cnt ) => html `${ cnt === 0 ? '' : '┃' } < span > ${ scope } </ span > ` ) }
504
- </ div >
505
- </ div > `
506
- : ''
507
- }
510
+ ${ scopeHtml }
508
511
</ div > `
509
512
: andSecurityItem . type === 'http'
510
513
? html `
511
514
< div >
512
515
${ orSecurityItem1 . securityDefs . length > 1 ? html `< b > ${ j + 1 } .</ b > ` : html `Requires` }
513
516
${ andSecurityItem . scheme === 'basic' ? 'Base 64 encoded username:password' : 'Bearer Token' } in < b > Authorization header</ b >
517
+ ${ scopeHtml }
514
518
</ div > `
515
519
: html `
516
520
< div >
517
521
${ orSecurityItem1 . securityDefs . length > 1 ? html `< b > ${ j + 1 } .</ b > ` : html `Requires` }
518
522
Token in < b > ${ andSecurityItem . name } ${ andSecurityItem . in } </ b >
523
+ ${ scopeHtml }
519
524
</ div > `
520
- }
521
- ` ) }
525
+ } ` ;
526
+ } ) }
522
527
</ div >
523
528
</ div >
524
529
</ div >
0 commit comments