@@ -28,14 +28,12 @@ export default class ApiRequest extends LitElement {
28
28
29
29
static get properties ( ) {
30
30
return {
31
- apiKeyName : { type : String , attribute : 'api-key-name' } ,
32
- apiKeyValue : { type : String , attribute : 'api-key-value' } ,
33
- apiKeyLocation : { type : String , attribute : 'api-key-location' } ,
34
31
selectedServer : { type : String , attribute : 'selected-server' } ,
35
32
method : { type : String } ,
36
33
path : { type : String } ,
37
34
parameters : { type : Array } ,
38
35
request_body : { type : Object } ,
36
+ api_keys : { type : Array } ,
39
37
parser : { type : Object } ,
40
38
accept : { type : String } ,
41
39
responseMessage : { type : String , attribute : false } ,
@@ -104,7 +102,7 @@ export default class ApiRequest extends LitElement {
104
102
color : var (--blue );
105
103
}
106
104
107
- @media only screen and (min-width : 768px ){
105
+ @media only screen and (min-width : 768px ) {
108
106
.textarea {
109
107
padding : 16px ;
110
108
}
@@ -463,21 +461,23 @@ export default class ApiRequest extends LitElement {
463
461
return html `
464
462
< div style ="display:flex; align-items: center; margin:16px 0; font-size:var(--font-size-small); ">
465
463
< div style ="display:flex; flex-direction:column; margin:0; width:calc(100% - 60px); ">
466
- < div style ="display:flex;flex-direction:row;overflow:hidden; "> < div style ="font-weight:bold;padding-right:5px; "> API SERVER: </ div >
464
+ < div style ="display:flex;flex-direction:row;overflow:hidden; ">
465
+ < div style ="font-weight:bold;padding-right:5px; "> API SERVER: </ div >
467
466
${ this . selectedServer
468
467
? html `${ this . selectedServer } `
469
468
: html `< div style ="font-weight:bold;color:var(--red) "> Not Set</ div > `
470
469
}
471
470
</ div >
472
- < div style ="display:flex;flex-direction:row;overflow:hidden;line-height:16px;color:var(--fg3) ">
473
- ${ this . apiKeyValue && this . apiKeyName
474
- ? html `
475
- < div style ="font-weight:bold;color:var(--blue) "> Authentication: </ div >
476
- send < div style ="font-family:var(--font-mono); color:var(--fg) "> '${ this . apiKeyName } ' </ div >
477
- in< div style ="font-family:var(--font-mono); color:var(--fg) "> '${ this . apiKeyLocation } ' </ div >
478
- with value< div style ="font-family:var(--font-mono); color:var(--fg) "> '${ `${ this . apiKeyValue . substring ( 0 , 3 ) } ***` } ' </ div >
479
- `
480
- : html `< div style ="color:var(--light-fg) "> No Authentication Token provided</ div > `
471
+ < div style ="display:flex; ">
472
+ < div style ="padding-right:5px; "> Authentication: </ div >
473
+ ${ this . api_keys . length > 0
474
+ ? html `< div style ="font-weight:bold;color:var(--blue); overflow:hidden; ">
475
+ ${ this . api_keys . length === 1
476
+ ? `API Key '${ this . api_keys [ 0 ] . name } ' in ${ this . api_keys [ 0 ] . in } `
477
+ : `${ this . api_keys . length } API keys applied`
478
+ }
479
+ </ div > `
480
+ : html `< div style ="font-weight:bold; color:var(--red) "> No API key applied</ div > `
481
481
}
482
482
</ div >
483
483
</ div >
@@ -626,9 +626,11 @@ export default class ApiRequest extends LitElement {
626
626
627
627
628
628
// Add authentication Query-Param if provided
629
- if ( this . apiKeyValue && this . apiKeyName && this . apiKeyLocation === 'query' ) {
630
- fetchUrl = `${ fetchUrl } ${ fetchUrl . includes ( '?' ) ? '&' : '?' } ${ this . apiKeyName } =${ encodeURIComponent ( this . apiKeyValue ) } ` ;
631
- }
629
+ this . api_keys
630
+ . filter ( ( v ) => ( v . in === 'query' ) )
631
+ . forEach ( ( v ) => {
632
+ fetchUrl = `${ fetchUrl } ${ fetchUrl . includes ( '?' ) ? '&' : '?' } ${ v . name } =${ encodeURIComponent ( v . finalKeyValue ) } ` ;
633
+ } ) ;
632
634
633
635
// Final URL for API call
634
636
fetchUrl = `${ this . selectedServer . replace ( / \/ $ / , '' ) } ${ fetchUrl } ` ;
@@ -653,10 +655,12 @@ export default class ApiRequest extends LitElement {
653
655
}
654
656
} ) ;
655
657
// Add Authentication Header if provided
656
- if ( this . apiKeyValue && this . apiKeyName && this . apiKeyLocation === 'header' ) {
657
- fetchOptions . headers [ this . apiKeyName ] = this . apiKeyValue ;
658
- curlHeaders += ` -H "${ this . apiKeyName } : ${ this . apiKeyValue } "` ;
659
- }
658
+ this . api_keys
659
+ . filter ( ( v ) => ( v . in === 'header' ) )
660
+ . forEach ( ( v ) => {
661
+ fetchOptions . headers [ v . name ] = v . finalKeyValue ;
662
+ curlHeaders += ` -H "${ v . name } : ${ v . finalKeyValue } "` ;
663
+ } ) ;
660
664
661
665
// Submit Form Params (url-encoded or form-data)
662
666
if ( formParamEls . length >= 1 ) {
0 commit comments