ciyidogan commited on
Commit
f5d0d9a
·
verified ·
1 Parent(s): 2018b55

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
@@ -46,7 +46,7 @@ export default class ApiEditDialogComponent implements OnInit {
46
  testResult: any = null;
47
  testRequestJson = '{}';
48
  allIntentParameters: { name: string; type: string }[] = [];
49
- responseMappingVariables: string[] = [];
50
 
51
  httpMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
52
  retryStrategies = ['static', 'exponential'];
@@ -252,27 +252,27 @@ export default class ApiEditDialogComponent implements OnInit {
252
 
253
  getTemplateVariables(includeResponseMappings = true): string[] {
254
  const variables = new Set<string>();
255
-
256
  // Intent parameters
257
  this.allIntentParameters.forEach(param => {
258
- variables.add(`variables.${param}`);
259
  });
260
-
261
  // Auth tokens
262
  const apiName = this.form.get('name')?.value || 'api_name';
263
  variables.add(`auth_tokens.${apiName}.token`);
264
-
265
  // Response mappings
266
  if (includeResponseMappings) {
267
  this.responseMappingVariables.forEach(varName => {
268
  variables.add(`variables.${varName}`);
269
  });
270
  }
271
-
272
  // Config variables
273
  variables.add('config.work_mode');
274
  variables.add('config.cloud_token');
275
-
276
  return Array.from(variables).sort();
277
  }
278
 
@@ -280,8 +280,11 @@ export default class ApiEditDialogComponent implements OnInit {
280
  this.responseMappingVariables = [];
281
  const mappings = this.responseMappings.value;
282
  mappings.forEach((mapping: any) => {
283
- if (mapping.variable_name) {
284
- this.responseMappingVariables.push(mapping.variable_name);
 
 
 
285
  }
286
  });
287
  }
@@ -319,51 +322,51 @@ export default class ApiEditDialogComponent implements OnInit {
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
 
 
46
  testResult: any = null;
47
  testRequestJson = '{}';
48
  allIntentParameters: { name: string; type: string }[] = [];
49
+ responseMappingVariables: { name: string; type: string }[] = [];
50
 
51
  httpMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
52
  retryStrategies = ['static', 'exponential'];
 
252
 
253
  getTemplateVariables(includeResponseMappings = true): string[] {
254
  const variables = new Set<string>();
255
+
256
  // Intent parameters
257
  this.allIntentParameters.forEach(param => {
258
+ variables.add(`variables.${param.name}`); // param artık object
259
  });
260
+
261
  // Auth tokens
262
  const apiName = this.form.get('name')?.value || 'api_name';
263
  variables.add(`auth_tokens.${apiName}.token`);
264
+
265
  // Response mappings
266
  if (includeResponseMappings) {
267
  this.responseMappingVariables.forEach(varName => {
268
  variables.add(`variables.${varName}`);
269
  });
270
  }
271
+
272
  // Config variables
273
  variables.add('config.work_mode');
274
  variables.add('config.cloud_token');
275
+
276
  return Array.from(variables).sort();
277
  }
278
 
 
280
  this.responseMappingVariables = [];
281
  const mappings = this.responseMappings.value;
282
  mappings.forEach((mapping: any) => {
283
+ if (mapping.variable_name && mapping.type) {
284
+ this.responseMappingVariables.push({
285
+ name: mapping.variable_name,
286
+ type: mapping.type
287
+ });
288
  }
289
  });
290
  }
 
322
  try {
323
  let jsonStr = control.value;
324
 
 
325
  jsonStr = jsonStr.replace(/\{\{([^}]+)\}\}/g, (match, variablePath) => {
326
  const path = variablePath.trim();
327
 
 
328
  if (path.startsWith('variables.')) {
329
  const varName = path.split('.')[1];
330
 
331
+ // Önce intent parametrelerinde ara
332
  const param = this.allIntentParameters.find(p => p.name === varName);
 
333
  if (param) {
334
  switch (param.type) {
335
+ case 'int': return '123';
336
+ case 'float': return '123.45';
337
+ case 'bool': return 'true';
338
+ case 'date': return '"2025-01-01"';
339
+ default: return '"placeholder"';
340
+ }
341
+ }
342
+
343
+ // Response mapping'lerde ara
344
+ const responseVar = this.responseMappingVariables.find(v => v.name === varName);
345
+ if (responseVar) {
346
+ switch (responseVar.type) {
347
+ case 'int': return '123';
348
+ case 'float': return '123.45';
349
+ case 'bool': return 'true';
350
+ case 'date': return '"2025-01-01"';
351
+ default: return '"placeholder"';
352
  }
353
  }
354
 
355
+ // Tanımsız değişken
356
  return '"UNDEFINED_VARIABLE"';
357
  }
358
 
 
359
  if (path.startsWith('auth_tokens.')) {
360
  return '"token123"';
361
  }
362
 
 
363
  if (path.startsWith('config.')) {
364
  return '"configvalue"';
365
  }
366
 
 
367
  return '"unknown"';
368
  });
369
 
 
370
  JSON.parse(jsonStr);
371
  return true;
372