Skip to content

Commit 15467a5

Browse files
committed
feat: validate required parameters before executing API request.
Signed-off-by: Yash-Raj-5424 <myash3499@gmail.com>
1 parent 6827985 commit 15467a5

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

static/js/rest-api-executor.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ class RESTAPIExecutor {
6868
// Get operation metadata from data attributes
6969
const operation = this.getOperationMetadata(operationPanel);
7070

71+
// Validate required parameters before executing
72+
const validationError = this.validateRequiredParameters(operationPanel);
73+
if (validationError) {
74+
this.displayError(operationPanel, validationError);
75+
return;
76+
}
77+
7178
// Build the complete URL with parameters
7279
const url = this.buildRequestUrl(operationPanel, operation);
7380

@@ -141,6 +148,32 @@ class RESTAPIExecutor {
141148
}
142149
}
143150

151+
/**
152+
* Validate that all required parameters are provided
153+
* @param {Element} operationPanel - The operation panel element
154+
* @returns {Error|null} Error object if validation fails, null otherwise
155+
*/
156+
validateRequiredParameters(operationPanel) {
157+
const requiredInputs = operationPanel.querySelectorAll('[data-parameter-input][required]');
158+
const missingParams = [];
159+
160+
requiredInputs.forEach(input => {
161+
if (!input.value || input.value.trim() === '') {
162+
const paramName = input.dataset.parameterName;
163+
const paramLocation = input.dataset.parameterLocation;
164+
missingParams.push(`${paramName} (${paramLocation})`);
165+
}
166+
});
167+
168+
if (missingParams.length > 0) {
169+
const error = new Error(`Required parameters are missing: ${missingParams.join(', ')}`);
170+
error.validationError = true;
171+
return error;
172+
}
173+
174+
return null;
175+
}
176+
144177
/**
145178
* Get operation metadata from the panel
146179
* @param {Element} operationPanel - The operation panel element

0 commit comments

Comments
 (0)