Spaces:
Running
Running
Update flare-ui/src/app/dialogs/api-edit-dialog/api-edit-dialog.component.ts
Browse files
flare-ui/src/app/dialogs/api-edit-dialog/api-edit-dialog.component.ts
CHANGED
@@ -45,7 +45,7 @@ export default class ApiEditDialogComponent implements OnInit {
|
|
45 |
testing = false;
|
46 |
testResult: any = null;
|
47 |
testRequestJson = '{}';
|
48 |
-
allIntentParameters: string[] = [];
|
49 |
responseMappingVariables: string[] = [];
|
50 |
|
51 |
httpMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
@@ -288,23 +288,25 @@ export default class ApiEditDialogComponent implements OnInit {
|
|
288 |
|
289 |
async loadIntentParameters() {
|
290 |
try {
|
291 |
-
// Tüm projeleri al
|
292 |
const projects = await this.apiService.getProjects(false).toPromise();
|
293 |
-
const params = new
|
294 |
-
|
295 |
projects?.forEach(project => {
|
296 |
project.versions?.forEach(version => {
|
297 |
version.intents?.forEach(intent => {
|
298 |
intent.parameters?.forEach((param: any) => {
|
299 |
-
if (param.variable_name) {
|
300 |
-
params.
|
301 |
}
|
302 |
});
|
303 |
});
|
304 |
});
|
305 |
});
|
306 |
-
|
307 |
-
this.allIntentParameters = Array.from(params
|
|
|
|
|
|
|
308 |
} catch (error) {
|
309 |
console.error('Failed to load intent parameters:', error);
|
310 |
}
|
@@ -313,16 +315,59 @@ export default class ApiEditDialogComponent implements OnInit {
|
|
313 |
validateJSON(field: string): boolean {
|
314 |
const control = this.form.get(field);
|
315 |
if (!control || !control.value) return true;
|
316 |
-
|
317 |
try {
|
318 |
-
|
319 |
|
320 |
-
// Template değişkenlerini
|
321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
|
323 |
-
|
|
|
324 |
return true;
|
325 |
-
|
|
|
326 |
return false;
|
327 |
}
|
328 |
}
|
|
|
45 |
testing = false;
|
46 |
testResult: any = null;
|
47 |
testRequestJson = '{}';
|
48 |
+
allIntentParameters: { name: string; type: string }[] = [];
|
49 |
responseMappingVariables: string[] = [];
|
50 |
|
51 |
httpMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
|
|
288 |
|
289 |
async loadIntentParameters() {
|
290 |
try {
|
|
|
291 |
const projects = await this.apiService.getProjects(false).toPromise();
|
292 |
+
const params = new Map<string, string>();
|
293 |
+
|
294 |
projects?.forEach(project => {
|
295 |
project.versions?.forEach(version => {
|
296 |
version.intents?.forEach(intent => {
|
297 |
intent.parameters?.forEach((param: any) => {
|
298 |
+
if (param.variable_name && param.type) {
|
299 |
+
params.set(param.variable_name, param.type);
|
300 |
}
|
301 |
});
|
302 |
});
|
303 |
});
|
304 |
});
|
305 |
+
|
306 |
+
this.allIntentParameters = Array.from(params.entries())
|
307 |
+
.map(([name, type]) => ({ name, type }))
|
308 |
+
.sort((a, b) => a.name.localeCompare(b.name));
|
309 |
+
|
310 |
} catch (error) {
|
311 |
console.error('Failed to load intent parameters:', error);
|
312 |
}
|
|
|
315 |
validateJSON(field: string): boolean {
|
316 |
const control = this.form.get(field);
|
317 |
if (!control || !control.value) return true;
|
318 |
+
|
319 |
try {
|
320 |
+
let jsonStr = control.value;
|
321 |
|
322 |
+
// Template değişkenlerini tipine göre uygun değerlerle değiştir
|
323 |
+
jsonStr = jsonStr.replace(/\{\{([^}]+)\}\}/g, (match, variablePath) => {
|
324 |
+
const path = variablePath.trim();
|
325 |
+
|
326 |
+
// variables.xxx formatında mı?
|
327 |
+
if (path.startsWith('variables.')) {
|
328 |
+
const varName = path.split('.')[1];
|
329 |
+
|
330 |
+
// Intent parametrelerinden tip bilgisini bul
|
331 |
+
const param = this.allIntentParameters.find(p => p.name === varName);
|
332 |
+
|
333 |
+
if (param) {
|
334 |
+
switch (param.type) {
|
335 |
+
case 'int':
|
336 |
+
return '123';
|
337 |
+
case 'float':
|
338 |
+
return '123.45';
|
339 |
+
case 'bool':
|
340 |
+
return 'true';
|
341 |
+
case 'date':
|
342 |
+
return '"2025-01-01"';
|
343 |
+
default: // str
|
344 |
+
return '"placeholder"';
|
345 |
+
}
|
346 |
+
}
|
347 |
+
|
348 |
+
// Tanımsız değişken - hata durumu
|
349 |
+
return '"UNDEFINED_VARIABLE"';
|
350 |
+
}
|
351 |
+
|
352 |
+
// auth_tokens her zaman string
|
353 |
+
if (path.startsWith('auth_tokens.')) {
|
354 |
+
return '"token123"';
|
355 |
+
}
|
356 |
+
|
357 |
+
// config değerleri de string
|
358 |
+
if (path.startsWith('config.')) {
|
359 |
+
return '"configvalue"';
|
360 |
+
}
|
361 |
+
|
362 |
+
// Bilinmeyen prefix
|
363 |
+
return '"unknown"';
|
364 |
+
});
|
365 |
|
366 |
+
// Parse et
|
367 |
+
JSON.parse(jsonStr);
|
368 |
return true;
|
369 |
+
|
370 |
+
} catch (e) {
|
371 |
return false;
|
372 |
}
|
373 |
}
|