openapi-explorer 0.11.464 → 0.11.467

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -465,8 +465,8 @@ class ApiRequest extends _lit.LitElement {
465
465
  </pre> </div>`} <div class="tab-content col m-markdown" style="flex:1;display:${this.activeResponseTab === 'headers' ? 'flex' : 'none'}"> <button class="m-btn outline-primary toolbar-copy-btn" @click="${e => {
466
466
  (0, _commonUtils.copyToClipboard)(this.responseHeaders, e);
467
467
  }}" part="btn btn-fill">${(0, _languages.getI18nText)('operations.copy')}</button> <pre><code>${(0, _unsafeHtml.unsafeHTML)(_prismjs.default.highlight(this.responseHeaders, _prismjs.default.languages.css, 'css'))}</code></pre> </div> <div class="tab-content col m-markdown" style="flex:1;display:${this.activeResponseTab === 'curl' ? 'flex' : 'none'}"> <button class="m-btn outline-primary toolbar-copy-btn" @click="${e => {
468
- (0, _commonUtils.copyToClipboard)(this.curlSyntax.replace(/\\$/, ''), e);
469
- }}" part="btn btn-fill">${(0, _languages.getI18nText)('operations.copy')}</button> <pre><code>${(0, _unsafeHtml.unsafeHTML)(_prismjs.default.highlight(this.curlSyntax.trim().replace(/\\$/, ''), _prismjs.default.languages.shell, 'shell'))}</code></pre> </div> </div>`;
468
+ (0, _commonUtils.copyToClipboard)(this.curlSyntax, e);
469
+ }}" part="btn btn-fill">${(0, _languages.getI18nText)('operations.copy')}</button> <pre><code>${(0, _unsafeHtml.unsafeHTML)(_prismjs.default.highlight(this.curlSyntax.trim(), _prismjs.default.languages.shell, 'shell'))}</code></pre> </div> </div>`;
470
470
  }
471
471
 
472
472
  apiCallTemplate() {
@@ -494,38 +494,39 @@ class ApiRequest extends _lit.LitElement {
494
494
 
495
495
  async onTryClick() {
496
496
  const tryBtnEl = this.querySelectorAll('.btn-execute')[0];
497
- let fetchUrl;
498
- let curlUrl;
499
- let curl = '';
500
- let curlHeaders = '';
501
497
  let curlData = '';
502
498
  let curlForm = '';
503
499
  const closestRespContainer = this.closest('.expanded-req-resp-container, .req-resp-container');
504
500
  const respEl = closestRespContainer && closestRespContainer.getElementsByTagName('api-response')[0];
505
- const acceptHeader = respEl && respEl.selectedMimeType;
501
+ const acceptHeader = respEl === null || respEl === void 0 ? void 0 : respEl.selectedMimeType;
506
502
  const requestPanelEl = this.closest('.request-panel');
507
503
  const pathParamEls = [...requestPanelEl.querySelectorAll("[data-ptype='path']")];
508
504
  const queryParamEls = [...requestPanelEl.querySelectorAll("[data-ptype='query']")];
509
505
  const queryParamObjTypeEls = [...requestPanelEl.querySelectorAll("[data-ptype='query-object']")];
510
506
  const headerParamEls = [...requestPanelEl.querySelectorAll("[data-ptype='header']")];
511
507
  const requestBodyContainerEl = requestPanelEl.querySelector('.request-body-container');
512
- fetchUrl = this.path.replaceAll(' ', '');
513
- const fetchOptions = {
514
- method: this.method.toUpperCase(),
515
- headers: new Headers()
516
- }; // Generate URL using Path Params
508
+ let pathUrl = `${this.serverUrl.replace(/\/$/, '')}${this.path.replaceAll(' ', '')}`; // Generate URL using Path Params
517
509
 
518
510
  pathParamEls.map(el => {
519
- fetchUrl = fetchUrl.replace(`{${el.dataset.pname}}`, encodeURIComponent(el.value));
520
- }); // Query Params
511
+ pathUrl = pathUrl.replace(`{${el.dataset.pname}}`, encodeURIComponent(el.value) || '-');
512
+ }); // Handle relative serverUrls
521
513
 
522
- const urlQueryParam = new URLSearchParams();
514
+ if (!pathUrl.startsWith('http')) {
515
+ const newUrl = new URL(pathUrl, window.location.href);
516
+ pathUrl = newUrl.toString();
517
+ }
518
+
519
+ const fetchUrl = new URL(pathUrl);
520
+ const fetchOptions = {
521
+ method: this.method.toUpperCase(),
522
+ headers: new Headers()
523
+ }; // Query Params
523
524
 
524
525
  if (queryParamEls.length > 0) {
525
526
  queryParamEls.forEach(el => {
526
527
  if (el.dataset.array === 'false') {
527
528
  if (el.value !== '') {
528
- urlQueryParam.append(el.dataset.pname, el.value);
529
+ fetchUrl.searchParams.append(el.dataset.pname, el.value);
529
530
  }
530
531
  } else {
531
532
  const paramSerializeStyle = el.dataset.paramSerializeStyle;
@@ -535,17 +536,17 @@ class ApiRequest extends _lit.LitElement {
535
536
 
536
537
  if (vals.length > 0) {
537
538
  if (paramSerializeStyle === 'spaceDelimited') {
538
- urlQueryParam.append(el.dataset.pname, vals.join(' ').replace(/^\s|\s$/g, ''));
539
+ fetchUrl.searchParams.append(el.dataset.pname, vals.join(' ').replace(/^\s|\s$/g, ''));
539
540
  } else if (paramSerializeStyle === 'pipeDelimited') {
540
- urlQueryParam.append(el.dataset.pname, vals.join('|').replace(/^\||\|$/g, ''));
541
+ fetchUrl.searchParams.append(el.dataset.pname, vals.join('|').replace(/^\||\|$/g, ''));
541
542
  } else {
542
543
  if (paramSerializeExplode === 'true') {
543
544
  // eslint-disable-line no-lonely-if
544
545
  vals.forEach(v => {
545
- urlQueryParam.append(el.dataset.pname, v);
546
+ fetchUrl.searchParams.append(el.dataset.pname, v);
546
547
  });
547
548
  } else {
548
- urlQueryParam.append(el.dataset.pname, vals.join(',').replace(/^,|,$/g, ''));
549
+ fetchUrl.searchParams.append(el.dataset.pname, vals.join(',').replace(/^,|,$/g, ''));
549
550
  }
550
551
  }
551
552
  }
@@ -566,22 +567,22 @@ class ApiRequest extends _lit.LitElement {
566
567
  if (typeof queryParamObj[key] === 'object') {
567
568
  if (Array.isArray(queryParamObj[key])) {
568
569
  if (paramSerializeStyle === 'spaceDelimited') {
569
- urlQueryParam.append(key, queryParamObj[key].join(' '));
570
+ fetchUrl.searchParams.append(key, queryParamObj[key].join(' '));
570
571
  } else if (paramSerializeStyle === 'pipeDelimited') {
571
- urlQueryParam.append(key, queryParamObj[key].join('|'));
572
+ fetchUrl.searchParams.append(key, queryParamObj[key].join('|'));
572
573
  } else {
573
574
  if (paramSerializeExplode === 'true') {
574
575
  // eslint-disable-line no-lonely-if
575
576
  queryParamObj[key].forEach(v => {
576
- urlQueryParam.append(key, v);
577
+ fetchUrl.searchParams.append(key, v);
577
578
  });
578
579
  } else {
579
- urlQueryParam.append(key, queryParamObj[key]);
580
+ fetchUrl.searchParams.append(key, queryParamObj[key]);
580
581
  }
581
582
  }
582
583
  }
583
584
  } else {
584
- urlQueryParam.append(key, queryParamObj[key]);
585
+ fetchUrl.searchParams.append(key, queryParamObj[key]);
585
586
  }
586
587
  }
587
588
  } catch (err) {
@@ -593,41 +594,25 @@ class ApiRequest extends _lit.LitElement {
593
594
 
594
595
  this.api_keys.filter(v => v.finalKeyValue).forEach(v => {
595
596
  if (v.in === 'query') {
596
- urlQueryParam.append(v.name, v.finalKeyValue);
597
+ fetchUrl.searchParams.append(v.name, v.finalKeyValue);
597
598
  return;
598
599
  } // Otherwise put it in the header
599
600
 
600
601
 
601
602
  fetchOptions.headers.append(v.name, v.finalKeyValue);
602
- curlHeaders += ` -H "${v.name}: ${v.finalKeyValue}" \\\n`;
603
603
  });
604
- fetchUrl = `${fetchUrl}${urlQueryParam.toString() ? '?' : ''}${urlQueryParam.toString()}`; // Final URL for API call
605
-
606
- fetchUrl = `${this.serverUrl.replace(/\/$/, '')}${fetchUrl}`;
607
-
608
- if (fetchUrl.startsWith('http') === false) {
609
- const url = new URL(fetchUrl, window.location.href);
610
- curlUrl = url.href;
611
- } else {
612
- curlUrl = fetchUrl;
613
- }
614
-
615
- curl = `curl -X ${this.method.toUpperCase()} "${curlUrl}" \\\n`;
616
604
 
617
605
  if (acceptHeader) {
618
606
  // Uses the acceptHeader from Response panel
619
607
  fetchOptions.headers.append('Accept', acceptHeader);
620
- curlHeaders += ` -H "Accept: ${acceptHeader}" \\\n`;
621
608
  } else if (this.accept) {
622
609
  fetchOptions.headers.append('Accept', this.accept);
623
- curlHeaders += ` -H "Accept: ${this.accept}" \\\n`;
624
610
  } // Add Header Params
625
611
 
626
612
 
627
613
  headerParamEls.map(el => {
628
614
  if (el.value) {
629
615
  fetchOptions.headers.append(el.dataset.pname, el.value);
630
- curlHeaders += ` -H "${el.dataset.pname}: ${el.value}" \\\n`;
631
616
  }
632
617
  }); // Request Body Params
633
618
 
@@ -661,7 +646,7 @@ class ApiRequest extends _lit.LitElement {
661
646
  }
662
647
 
663
648
  fetchOptions.body = formUrlDynParams;
664
- curlData = ` -d ${formUrlDynParams.toString()} \\\n`;
649
+ curlData = ` \\\n -d ${formUrlDynParams.toString()}`;
665
650
  }
666
651
  } else {
667
652
  // url-encoded Form Params (regular)
@@ -678,7 +663,7 @@ class ApiRequest extends _lit.LitElement {
678
663
  }
679
664
  });
680
665
  fetchOptions.body = formUrlParams;
681
- curlData = ` -d ${formUrlParams.toString()} \\\n`;
666
+ curlData = ` \\\n -d ${formUrlParams.toString()}`;
682
667
  }
683
668
  } else if (requestBodyType.includes('form-data')) {
684
669
  const formDataParams = new FormData();
@@ -687,14 +672,14 @@ class ApiRequest extends _lit.LitElement {
687
672
  if (el.dataset.array === 'false') {
688
673
  if (el.type === 'file' && el.files[0]) {
689
674
  formDataParams.append(el.dataset.pname, el.files[0], el.files[0].name);
690
- curlForm += ` -F "${el.dataset.pname}=@${el.files[0].name}" \\\n`;
675
+ curlForm += ` \\\n -F "${el.dataset.pname}=@${el.files[0].name}"`;
691
676
  } else if (el.value) {
692
677
  formDataParams.append(el.dataset.pname, el.value);
693
- curlForm += ` -F "${el.dataset.pname}=${el.value}" \\\n`;
678
+ curlForm += ` \\\n -F "${el.dataset.pname}=${el.value}"`;
694
679
  }
695
680
  } else if (el.value && Array.isArray(el.value)) {
696
681
  el.value.forEach(v => {
697
- curlForm = `${curlForm} -F "${el.dataset.pname}[]=${v}" \\\n`;
682
+ curlForm += ` \\\n -F "${el.dataset.pname}[]=${v}"`;
698
683
  });
699
684
  formDataParams.append(el.dataset.pname, el.value.join(','));
700
685
  }
@@ -705,7 +690,7 @@ class ApiRequest extends _lit.LitElement {
705
690
 
706
691
  if (bodyParamFileEl && bodyParamFileEl.files[0]) {
707
692
  fetchOptions.body = bodyParamFileEl.files[0];
708
- curlData = ` --data-binary @${bodyParamFileEl.files[0].name} \\\n`;
693
+ curlData = ` \\\n --data-binary @${bodyParamFileEl.files[0].name}`;
709
694
  }
710
695
  } else if (requestBodyType.includes('json') || requestBodyType.includes('xml') || requestBodyType.includes('text')) {
711
696
  const exampleTextAreaEl = requestPanelEl.querySelector('.request-body-param-user-input');
@@ -715,7 +700,7 @@ class ApiRequest extends _lit.LitElement {
715
700
 
716
701
  if (requestBodyType.includes('json')) {
717
702
  try {
718
- curlData = ` -d '${JSON.stringify(JSON.parse(exampleTextAreaEl.value))}' \\\n`;
703
+ curlData = ` \\\n -d '${JSON.stringify(JSON.parse(exampleTextAreaEl.value))}'`;
719
704
  } catch (err) {
720
705
  /* Ignore unparseable JSON */
721
706
  }
@@ -723,7 +708,7 @@ class ApiRequest extends _lit.LitElement {
723
708
 
724
709
  if (!curlData) {
725
710
  // Save single quotes wrapped => 'text' => `"'"text"'"`
726
- curlData = ` -d '${exampleTextAreaEl.value.replace(/'/g, '\'"\'"\'')}' \\\n`;
711
+ curlData = ` \\\n -d '${exampleTextAreaEl.value.replace(/'/g, '\'"\'"\'')}'`;
727
712
  }
728
713
  }
729
714
  } // Common for all request-body
@@ -733,11 +718,8 @@ class ApiRequest extends _lit.LitElement {
733
718
  // For multipart/form-data don't set the content-type to allow creation of browser generated part boundaries
734
719
  fetchOptions.headers.append('Content-Type', requestBodyType);
735
720
  }
736
-
737
- curlHeaders += ` -H "Content-Type: ${requestBodyType}" \\\n`;
738
721
  }
739
722
 
740
- this.curlSyntax = '';
741
723
  this.responseIsBlob = false;
742
724
  this.respContentDisposition = '';
743
725
 
@@ -746,8 +728,6 @@ class ApiRequest extends _lit.LitElement {
746
728
  this.responseBlobUrl = '';
747
729
  }
748
730
 
749
- this.curlSyntax = `${curl}${curlHeaders}${curlData}${curlForm}`;
750
-
751
731
  if (this.fetchCredentials) {
752
732
  fetchOptions.credentials = this.fetchCredentials;
753
733
  } // Options is legacy usage, documentation has been updated to reference properties of the fetch option directly, but older usages may still be using options
@@ -755,7 +735,7 @@ class ApiRequest extends _lit.LitElement {
755
735
 
756
736
  const fetchRequest = {
757
737
  explorerLocation: this.elementId,
758
- url: fetchUrl,
738
+ url: fetchUrl.toString(),
759
739
  options: fetchOptions,
760
740
  ...fetchOptions
761
741
  };
@@ -775,6 +755,9 @@ class ApiRequest extends _lit.LitElement {
775
755
  body: fetchRequest.body || fetchOptions.body
776
756
  };
777
757
  const fetchRequestObject = new Request(fetchRequest.url, newFetchOptions);
758
+ const curl = `curl -X ${this.method.toUpperCase()} "${fetchUrl.toString()}"`;
759
+ const curlHeaders = [...newFetchOptions.headers.entries()].reduce((acc, [key, value]) => `${acc} \\\n -H "${key}: ${value}"`, '');
760
+ this.curlSyntax = `${curl}${curlHeaders}${curlData}${curlForm}`;
778
761
  let fetchResponse;
779
762
 
780
763
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-explorer",
3
- "version": "0.11.464",
3
+ "version": "0.11.467",
4
4
  "description": "OpenAPI Explorer - API viewer with dynamically generated components, documentation, and interaction console",
5
5
  "author": "Rhosys Developers <developers@rhosys.ch>",
6
6
  "type": "module",