@@ -176,24 +176,34 @@ export default class ApiRequest extends LitElement {
176
176
}
177
177
</ div >
178
178
</ td >
179
- < td style ="width:160px; min-width:100px; ">
179
+ < td style ="width:${ paramSchema . type === 'array' || paramSchema . type === 'object' ? '220px' : ' 160px' } ; min-width:100px; ">
180
180
${ paramSchema . type === 'array'
181
181
? html `
182
182
< tag-input class ="request-param "
183
183
style = "width:160px; background:var(--input-bg);line-height:13px; "
184
- data-ptype = "${ paramType } "
184
+ data-ptype = "${ paramType } "
185
185
data-pname = "${ param . name } "
186
186
data-array = "true "
187
187
placeholder = "add-multiple \u23ce"
188
188
>
189
189
</ tag-input > `
190
- : html `
191
- < input type ="text " spellcheck ="false " style ="width:100% " class ="request-param "
192
- data-pname ="${ param . name } "
193
- data-ptype ="${ paramType } "
194
- data-array ="false "
195
- value ="${ inputVal } "
196
- /> `
190
+ : paramSchema . type === 'object'
191
+ ? html `
192
+ < textarea
193
+ class = "mono request-param "
194
+ data-ptype = "${ paramType } -object "
195
+ data-pname = "${ param . name } "
196
+ spellcheck = "false "
197
+ style = "resize:vertical; width:100%; height:120px; "
198
+ > </ textarea >
199
+ `
200
+ : html `
201
+ < input type ="text " spellcheck ="false " style ="width:100% " class ="request-param "
202
+ data-pname ="${ param . name } "
203
+ data-ptype ="${ paramType } "
204
+ data-array ="false "
205
+ value ="${ inputVal } "
206
+ /> `
197
207
}
198
208
</ td >
199
209
< td >
@@ -499,7 +509,7 @@ export default class ApiRequest extends LitElement {
499
509
}
500
510
/* eslint-enable indent */
501
511
502
- onMimeTypeChange ( e ) {
512
+ static onMimeTypeChange ( e ) {
503
513
const textareaEls = e . target . closest ( '.tab-panel' ) . querySelectorAll ( 'textarea.request-body-param' ) ;
504
514
const schemaTreeEls = e . target . closest ( '.tab-panel' ) . querySelectorAll ( 'schema-tree' ) ;
505
515
[ ...textareaEls ] . map ( ( el ) => {
@@ -523,6 +533,7 @@ export default class ApiRequest extends LitElement {
523
533
const requestPanelEl = e . target . closest ( '.request-panel' ) ;
524
534
const pathParamEls = [ ...requestPanelEl . querySelectorAll ( ".request-param[data-ptype='path']" ) ] ;
525
535
const queryParamEls = [ ...requestPanelEl . querySelectorAll ( ".request-param[data-ptype='query']" ) ] ;
536
+ const queryParamObjTypeEls = [ ...requestPanelEl . querySelectorAll ( ".request-param[data-ptype='query-object']" ) ] ;
526
537
const headerParamEls = [ ...requestPanelEl . querySelectorAll ( ".request-param[data-ptype='header']" ) ] ;
527
538
const formParamEls = [ ...requestPanelEl . querySelectorAll ( '.request-form-param' ) ] ;
528
539
const bodyParamEls = [ ...requestPanelEl . querySelectorAll ( '.request-body-param' ) ] ;
@@ -538,24 +549,44 @@ export default class ApiRequest extends LitElement {
538
549
fetchUrl = fetchUrl . replace ( `{${ el . dataset . pname } }` , el . value ) ;
539
550
} ) ;
540
551
541
- // Submit Query Params
552
+ // Collect Query Params
553
+ const urlQueryParam = new URLSearchParams ( '' ) ;
542
554
if ( queryParamEls . length > 0 ) {
543
- const queryParam = new URLSearchParams ( '' ) ;
544
555
queryParamEls . map ( ( el ) => {
545
556
if ( el . dataset . array === 'false' ) {
546
557
if ( el . value !== '' ) {
547
- queryParam . append ( el . dataset . pname , el . value ) ;
558
+ urlQueryParam . append ( el . dataset . pname , el . value ) ;
548
559
}
549
560
} else {
550
561
const vals = el . getValues ( ) ;
551
562
for ( const v of vals ) {
552
- queryParam . append ( el . dataset . pname , v ) ;
563
+ urlQueryParam . append ( el . dataset . pname , v ) ;
553
564
}
554
565
}
555
566
} ) ;
556
- fetchUrl = `${ fetchUrl } ?${ queryParam . toString ( ) } ` ;
557
567
}
558
568
569
+ // Collect Query Params from Object
570
+ if ( queryParamObjTypeEls . length > 0 ) {
571
+ let queryParamObj = { } ;
572
+ queryParamObjTypeEls . map ( ( el ) => {
573
+ try {
574
+ queryParamObj = Object . assign ( queryParamObj , JSON . parse ( el . value . replace ( / \s + / g, ' ' ) ) ) ;
575
+ } catch ( err ) {
576
+ console . log ( 'unable to parse %s into object' , el . value ) ; // eslint-disable-line no-console
577
+ }
578
+ } ) ;
579
+ if ( Object . keys ( queryParamObj ) . length > 0 ) {
580
+ for ( const key in queryParamObj ) {
581
+ urlQueryParam . append ( key , queryParamObj [ key ] ) ;
582
+ }
583
+ }
584
+ }
585
+ if ( urlQueryParam . toString ( ) . trim ( ) ) {
586
+ fetchUrl = `${ fetchUrl } ?${ urlQueryParam . toString ( ) } ` ;
587
+ }
588
+
589
+
559
590
// Add authentication Query-Param if provided
560
591
if ( this . apiKeyValue && this . apiKeyName && this . apiKeyLocation === 'query' ) {
561
592
fetchUrl = `${ fetchUrl } ${ fetchUrl . includes ( '?' ) ? '&' : '?' } ${ this . apiKeyName } =${ encodeURIComponent ( this . apiKeyValue ) } ` ;
0 commit comments