From 33a3abb38cc048fc643f4237b7d0ce81117abec8 Mon Sep 17 00:00:00 2001 From: Warren Parad Date: Fri, 15 Aug 2025 12:47:15 +0200 Subject: [PATCH] Fix clearing select. --- src/components/api-request.js | 23 +++++++++++++++-------- src/components/request-form-table.js | 3 --- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/api-request.js b/src/components/api-request.js index ea18f869..1ff717c7 100644 --- a/src/components/api-request.js +++ b/src/components/api-request.js @@ -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" @@ -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" @@ -209,7 +209,8 @@ export default class ApiRequest extends LitElement { ` } ${displayedBodyExample ? html` -
+
${displayedBodyExample.exampleSummary && displayedBodyExample.exampleSummary.length > 80 ? html`
${displayedBodyExample.exampleSummary}
` : ''} ${displayedBodyExample.exampleDescription ? html`
${unsafeHTML(toMarkdown(displayedBodyExample.exampleDescription || ''))}
` : ''} @@ -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)) : ''}" > @@ -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' } }; @@ -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() { diff --git a/src/components/request-form-table.js b/src/components/request-form-table.js index bb121484..35c1fd32 100644 --- a/src/components/request-form-table.js +++ b/src/components/request-form-table.js @@ -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 : ''}" // > @@ -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 || ''}" @@ -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" /> `;