mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
feat: remove unused openapi action button
This commit is contained in:
@@ -34,7 +34,10 @@ class DashbotActionWidgetFactory {
|
|||||||
case ChatActionType.applyCurl:
|
case ChatActionType.applyCurl:
|
||||||
return DashbotApplyCurlButton(action: action);
|
return DashbotApplyCurlButton(action: action);
|
||||||
case ChatActionType.applyOpenApi:
|
case ChatActionType.applyOpenApi:
|
||||||
return DashbotApplyOpenApiButton(action: action);
|
if (action.action == 'import_now_openapi') {
|
||||||
|
return DashbotImportNowButton(action: action);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
case ChatActionType.downloadDoc:
|
case ChatActionType.downloadDoc:
|
||||||
return DashbotDownloadDocButton(action: action);
|
return DashbotDownloadDocButton(action: action);
|
||||||
case ChatActionType.noAction:
|
case ChatActionType.noAction:
|
||||||
@@ -70,9 +73,6 @@ class DashbotActionWidgetFactory {
|
|||||||
if (action.action == 'apply_curl') {
|
if (action.action == 'apply_curl') {
|
||||||
return DashbotApplyCurlButton(action: action);
|
return DashbotApplyCurlButton(action: action);
|
||||||
}
|
}
|
||||||
if (action.action == 'apply_openapi') {
|
|
||||||
return DashbotApplyOpenApiButton(action: action);
|
|
||||||
}
|
|
||||||
if (action.action.contains('update') ||
|
if (action.action.contains('update') ||
|
||||||
action.action.contains('add') ||
|
action.action.contains('add') ||
|
||||||
action.action.contains('delete')) {
|
action.action.contains('delete')) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
export 'dashbot_add_test_button.dart';
|
export 'dashbot_add_test_button.dart';
|
||||||
export 'dashbot_apply_curl_button.dart';
|
export 'dashbot_apply_curl_button.dart';
|
||||||
export 'dashbot_apply_openapi_button.dart';
|
|
||||||
export 'dashbot_auto_fix_button.dart';
|
export 'dashbot_auto_fix_button.dart';
|
||||||
export 'dashbot_download_doc_button.dart';
|
export 'dashbot_download_doc_button.dart';
|
||||||
export 'dashbot_generate_codeblock.dart';
|
export 'dashbot_generate_codeblock.dart';
|
||||||
|
|||||||
@@ -233,34 +233,6 @@ class OpenApiImportService {
|
|||||||
op: op,
|
op: op,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Build an action message asking whether to apply to selected/new
|
|
||||||
/// for a single chosen operation.
|
|
||||||
static Map<String, dynamic> buildActionMessageFromPayload(
|
|
||||||
Map<String, dynamic> actionPayload,
|
|
||||||
{String? title}) {
|
|
||||||
final buf = StringBuffer(
|
|
||||||
title ?? 'Parsed the OpenAPI operation. Where should I apply it?');
|
|
||||||
return {
|
|
||||||
'explnation': buf.toString(),
|
|
||||||
'actions': [
|
|
||||||
{
|
|
||||||
'action': 'apply_openapi',
|
|
||||||
'target': 'httpRequestModel',
|
|
||||||
'field': 'apply_to_new',
|
|
||||||
'path': null,
|
|
||||||
'value': actionPayload,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'action': 'apply_openapi',
|
|
||||||
'target': 'httpRequestModel',
|
|
||||||
'field': 'apply_to_selected',
|
|
||||||
'path': null,
|
|
||||||
'value': actionPayload,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static Map<String, dynamic> buildOperationPicker(OpenApi spec,
|
static Map<String, dynamic> buildOperationPicker(OpenApi spec,
|
||||||
{String? insights}) {
|
{String? insights}) {
|
||||||
final servers = spec.servers ?? const [];
|
final servers = spec.servers ?? const [];
|
||||||
|
|||||||
@@ -445,27 +445,6 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
|||||||
collection.addRequestModel(model, name: displayName);
|
collection.addRequestModel(model, name: displayName);
|
||||||
_appendSystem('Created a new request from the OpenAPI operation.',
|
_appendSystem('Created a new request from the OpenAPI operation.',
|
||||||
ChatMessageType.importOpenApi);
|
ChatMessageType.importOpenApi);
|
||||||
} else if (action.field == 'select_operation') {
|
|
||||||
// Present apply options for the selected operation
|
|
||||||
final applyMsg = OpenApiImportService.buildActionMessageFromPayload(
|
|
||||||
payload,
|
|
||||||
title: 'Selected ${action.path}. Where should I apply it?',
|
|
||||||
);
|
|
||||||
final rqId = _currentRequest?.id ?? 'global';
|
|
||||||
_addMessage(
|
|
||||||
rqId,
|
|
||||||
ChatMessage(
|
|
||||||
id: getNewUuid(),
|
|
||||||
content: jsonEncode(applyMsg),
|
|
||||||
role: MessageRole.system,
|
|
||||||
timestamp: DateTime.now(),
|
|
||||||
messageType: ChatMessageType.importOpenApi,
|
|
||||||
actions: (applyMsg['actions'] as List)
|
|
||||||
.whereType<Map<String, dynamic>>()
|
|
||||||
.map(ChatAction.fromJson)
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,20 +69,6 @@ void main() {
|
|||||||
expect(payload['url'], 'https://api.apidash.dev/users');
|
expect(payload['url'], 'https://api.apidash.dev/users');
|
||||||
expect(payload['headers'], isA<Map>());
|
expect(payload['headers'], isA<Map>());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('buildActionMessageFromPayload returns two actions', () {
|
|
||||||
final op = spec.paths!['/users']!.post!;
|
|
||||||
final payload = OpenApiImportService.payloadForOperation(
|
|
||||||
baseUrl: spec.servers!.first.url!,
|
|
||||||
path: '/users',
|
|
||||||
method: 'post',
|
|
||||||
op: op,
|
|
||||||
);
|
|
||||||
final msg = OpenApiImportService.buildActionMessageFromPayload(payload);
|
|
||||||
final actions = (msg['actions'] as List).cast<Map<String, dynamic>>();
|
|
||||||
expect(actions.length, 2);
|
|
||||||
expect(actions.first['action'], 'apply_openapi');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
group('OpenApiImportService extended coverage', () {
|
group('OpenApiImportService extended coverage', () {
|
||||||
|
|||||||
Reference in New Issue
Block a user