Skip to content

Commit d44533d

Browse files
committed
Always update the curl display even when there is a validation triggered. fix #264
1 parent c697b02 commit d44533d

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

src/components/api-request.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ export default class ApiRequest extends LitElement {
9595
}
9696

9797
updated(changedProperties) {
98+
// When the operation is changed, reset the display view properties
99+
if (changedProperties.get('elementId')) {
100+
this.activeResponseTab = 'curl';
101+
}
98102
// In focused mode after rendering the request component, update the text-areas(which contains examples) using the original values from hidden textareas.
99103
// This is done coz, user may update the dom by editing the textarea's and once the DOM is updated externally change detection wont happen, therefore update the values manually
100104
if (this.renderStyle !== 'focused') {
101105
return;
102106
}
103107

104-
// dont update example as only tabs is switched
108+
// don't update example as only tabs is switched
105109
if (changedProperties.size === 1 && changedProperties.has('activeSchemaTab')) {
106110
return;
107111
}
@@ -624,7 +628,7 @@ export default class ApiRequest extends LitElement {
624628
}}">
625629
<br>
626630
<div style="width: 100%">
627-
<button class="tab-btn ${!hasResponse || this.activeResponseTab === 'curl' ? 'active' : ''}" data-tab = 'curl'>FULL REQUEST</button>
631+
<button class="tab-btn ${!hasResponse || this.activeResponseTab === 'curl' ? 'active' : ''}" data-tab = 'curl'>REQUEST</button>
628632
${!hasResponse ? '' : html`
629633
<button class="tab-btn ${this.activeResponseTab === 'response' ? 'active' : ''}" data-tab = 'response'>${getI18nText('operations.response')}</button>
630634
<button class="tab-btn ${this.activeResponseTab === 'headers' ? 'active' : ''}" data-tab = 'headers'>${getI18nText('operations.response-headers')}</button>`
@@ -654,10 +658,10 @@ export default class ApiRequest extends LitElement {
654658
</div>`
655659
}
656660
<div class="tab-content col m-markdown" style="flex:1;display:${this.activeResponseTab === 'headers' ? 'flex' : 'none'};" >
657-
<syntax-highlighter language="http" .content="${this.responseHeaders}"/>
661+
<syntax-highlighter style="min-height: 60px" language="http" .content="${this.responseHeaders}"/>
658662
</div>
659663
<div class="tab-content m-markdown col" style="flex:1;display:${this.activeResponseTab === 'curl' ? 'flex' : 'none'};">
660-
<syntax-highlighter language="shell" .content="${curlSyntax.trim()}"/>
664+
<syntax-highlighter style="min-height: 60px" language="shell" .content="${curlSyntax.trim()}"/>
661665
</div>
662666
</div>`;
663667
}
@@ -690,6 +694,17 @@ export default class ApiRequest extends LitElement {
690694
this.computeCurlSyntax();
691695
}
692696

697+
validateAllRequestParameters() {
698+
const requestPanelEl = this.closest('.request-panel');
699+
const pathParamEls = [...requestPanelEl.querySelectorAll("[data-ptype='path']")];
700+
const missingPathParameterValue = pathParamEls.find(el => !el.value);
701+
if (missingPathParameterValue) {
702+
const error = Error(`All path parameters are required and a valid value was not found for the parameter: '${missingPathParameterValue.dataset.pname}'.`);
703+
error.code = 'MissingPathParameter';
704+
throw error;
705+
}
706+
}
707+
693708
recomputeFetchOptions() {
694709
const requestPanelEl = this.closest('.request-panel');
695710
const pathParamEls = [...requestPanelEl.querySelectorAll("[data-ptype='path']")];
@@ -706,13 +721,6 @@ export default class ApiRequest extends LitElement {
706721
pathUrl = pathUrl.replace(`{${el.dataset.pname}}`, encodeURIComponent(el.value) || '-');
707722
});
708723

709-
const missingPathParameterValue = pathParamEls.find(el => !el.value);
710-
if (missingPathParameterValue) {
711-
const error = Error(`All path parameters are required and a valid value was not found for the parameter: '${missingPathParameterValue.dataset.pname}'.`);
712-
error.code = 'MissingPathParameter';
713-
throw error;
714-
}
715-
716724
// Handle relative serverUrls
717725
if (!pathUrl.startsWith('http')) {
718726
const newUrl = new URL(pathUrl, window.location.href);
@@ -920,6 +928,7 @@ export default class ApiRequest extends LitElement {
920928
let fetchUrl;
921929
let path;
922930
let query;
931+
923932
try {
924933
({ fetchOptions, fetchUrl, path, query } = this.recomputeFetchOptions());
925934
} catch (error) {
@@ -932,6 +941,17 @@ export default class ApiRequest extends LitElement {
932941
return;
933942
}
934943

944+
try {
945+
this.validateAllRequestParameters();
946+
} catch (error) {
947+
this.responseMessage = error.message;
948+
this.responseStatus = 'error';
949+
this.responseUrl = '';
950+
this.responseHeaders = '';
951+
this.responseText = '';
952+
return;
953+
}
954+
935955
this.responseIsBlob = false;
936956
this.respContentDisposition = '';
937957
if (this.responseBlobUrl) {

0 commit comments

Comments
 (0)