Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/components/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default class ApiRequest extends LitElement {
style = "width:100%;"
data-ptype = "${paramLocation}"
data-pname = "${paramName}"
data-default = "${Array.isArray(defaultVal) ? defaultVal.join('~|~') : defaultVal}"
data-required="${paramRequired}"
data-param-serialize-style = "${paramStyle}"
data-param-serialize-explode = "${paramExplode}"
data-array = "true"
Expand All @@ -198,7 +198,7 @@ export default class ApiRequest extends LitElement {
rows = 3
data-ptype = "${paramLocation}"
data-pname = "${paramName}"
data-default = "${defaultVal}"
data-required="${paramRequired}"
data-param-serialize-style = "${paramStyle}"
data-param-serialize-explode = "${paramExplode}"
spellcheck = "false"
Expand All @@ -209,7 +209,8 @@ export default class ApiRequest extends LitElement {
<select aria-label="mime type" style="width:100%; margin-top: 1rem; margin-bottom: 1rem;"
data-ptype="${paramLocation}"
data-pname="${paramName}"
.value="${this.fillRequestWithDefault === 'true' ? defaultVal : ''}"
data-required="${paramRequired}"
.value="${this.fillRequestWithDefault === 'true' ? defaultVal : (!generatedParamSchema.allowedValues.length || generatedParamSchema.allowedValues.some(v => v === null) ? null : generatedParamSchema.allowedValues[0])}"
@change="${(e) => { this.storedParamValues[paramName] = e; this.computeCurlSyntax(); }}">
${generatedParamSchema.allowedValues.map((allowedValue) => html`
<option value="${allowedValue}" ?selected = '${allowedValue === this.storedParamValues[paramName]}'>
Expand All @@ -228,7 +229,7 @@ export default class ApiRequest extends LitElement {
part="textbox textbox-param"
data-ptype="${paramLocation}"
data-pname="${paramName}"
data-default="${Array.isArray(defaultVal) ? defaultVal.join('~|~') : defaultVal}"
data-required="${paramRequired}"
data-array="false"
@keyup="${this.requestParamFunction}"
.value="${this.fillRequestWithDefault === 'true' ? defaultVal : ''}"
Expand Down Expand Up @@ -487,7 +488,7 @@ export default class ApiRequest extends LitElement {
</select>`
}
${displayedBodyExample ? html`
<div class="example" data-default = '${displayedBodyExample.exampleId}'>
<div class="example">
${displayedBodyExample.exampleSummary && displayedBodyExample.exampleSummary.length > 80 ? html`<div style="padding: 4px 0"> ${displayedBodyExample.exampleSummary} </div>` : ''}
${displayedBodyExample.exampleDescription ? html`<div class="m-markdown-small" style="padding: 4px 0"> ${unsafeHTML(toMarkdown(displayedBodyExample.exampleDescription || ''))} </div>` : ''}
<!-- this textarea is for user to edit the example -->
Expand All @@ -499,8 +500,6 @@ export default class ApiRequest extends LitElement {
aria-label = "${getI18nText('operations.request-body')}"
spellcheck = "false"
data-ptype = "${reqBody.mimeType}"
data-default = "${displayedBodyExample.exampleFormat === 'text' ? displayedBodyExample.exampleValue : JSON.stringify(displayedBodyExample.exampleValue, null, 8)}"
data-default-format = "${displayedBodyExample.exampleFormat}"
style="width:100%; resize:vertical;"
.value="${this.fillRequestWithDefault === 'true' ? (displayedBodyExample.exampleFormat === 'text' ? displayedBodyExample.exampleValue : JSON.stringify(displayedBodyExample.exampleValue, null, 8)) : ''}"
></textarea>
Expand Down Expand Up @@ -692,7 +691,7 @@ export default class ApiRequest extends LitElement {

onClearRequestData(e) {
const requestPanelEl = e.target.closest('.request-panel');
const requestPanelInputEls = [...requestPanelEl.querySelectorAll('input, tag-input, textarea:not(.is-hidden)')];
const requestPanelInputEls = [...requestPanelEl.querySelectorAll('input, select, tag-input, textarea:not(.is-hidden)')];
requestPanelInputEls.forEach((el) => { el.value = ''; });

const event = { bubbles: true, composed: true, detail: { explorerLocation: this.elementId, operation: { method: this.method, path: this.path }, type: 'RequestCleared' } };
Expand All @@ -709,6 +708,14 @@ export default class ApiRequest extends LitElement {
error.code = 'MissingPathParameter';
throw error;
}

const requiredPanelEl = [...requestPanelEl.querySelectorAll("[data-required='true']")];
const missingRequiredParameterValue = requiredPanelEl.find(el => !el.value);
if (missingRequiredParameterValue) {
const error = Error(`Required parameter found, but no valid value was set for the parameter: '${missingRequiredParameterValue.dataset.pname}'.`);
error.code = 'MissingRequiredParameter';
throw error;
}
}

recomputeFetchOptions() {
Expand Down
3 changes: 0 additions & 3 deletions src/components/request-form-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ function inputFieldKeyLabel(isOption, keyLabel, keyDescription, dataType, deprec
// data-array = "false"
// data-ptype = "form-input"
// data-pname = "${keyLabel}"
// data-default = "${defaultValue || ''}"
// spellcheck = "false"
// .value="${options.fillRequestWithDefault === 'true' ? defaultValue : ''}"
// ></textarea>
Expand Down Expand Up @@ -254,7 +253,6 @@ function getArrayFormField(keyLabel, example, defaultValue, format, rowGenerator
style = "width:100%;"
data-ptype = "form-input"
data-pname = "${keyLabel}"
data-default = "${defaultValue || ''}"
data-array = "true"
placeholder="${(Array.isArray(example) ? example[0] : example) || defaultValue || 'add-multiple ↩'}"
.value = "${defaultValue || ''}"
Expand All @@ -273,7 +271,6 @@ function getPrimitiveFormField(keyLabel, example, defaultValue, format, options,
style = "width:100%"
data-ptype = "form-input"
data-pname = "${keyLabel}"
data-default = "${defaultValue || ''}"
data-array = "false"
/>
</td>`;
Expand Down