mirror of
https://github.com/foss42/apidash.git
synced 2025-06-04 01:13:30 +08:00
Update insomnia_utils.dart
This commit is contained in:
@ -1,47 +1,25 @@
|
||||
|
||||
|
||||
|
||||
import 'package:insomnia_collection/models/insomnia_collection.dart';
|
||||
import 'package:insomnia_collection/models/insomnia_environment.dart';
|
||||
import '../models/models.dart';
|
||||
|
||||
List<(String?, Resource)> getRequestsFromInsomniaCollection(
|
||||
InsomniaCollection? ic) {
|
||||
if (ic == null || ic.resources == null) {
|
||||
InsomniaCollection? ic) =>
|
||||
getItemByTypeFromInsomniaCollection(ic, ResourceType.request.name);
|
||||
|
||||
List<(String?, Resource)> getEnvironmentsFromInsomniaCollection(
|
||||
InsomniaCollection? ic) =>
|
||||
getItemByTypeFromInsomniaCollection(ic, ResourceType.environment.name);
|
||||
|
||||
List<(String?, Resource)> getItemByTypeFromInsomniaCollection(
|
||||
InsomniaCollection? ic,
|
||||
String type,
|
||||
) {
|
||||
if (ic?.resources == null || ic!.resources!.length > 0) {
|
||||
return [];
|
||||
}
|
||||
List<(String?, Resource)> requests = [];
|
||||
if (ic.resources!.length > 0) {
|
||||
for (var i in ic.resources!) {
|
||||
requests.addAll(getRequestsFromInsomniaResource(i));
|
||||
for (var item in ic.resources!) {
|
||||
if (item.type != null || item.type == type) {
|
||||
requests.add((item.name, item));
|
||||
}
|
||||
}
|
||||
return requests;
|
||||
}
|
||||
|
||||
List<EnvironmentVariable> getEnvironmentVariablesFromInsomniaEnvironment(
|
||||
InsomniaEnvironment? ev) {
|
||||
if (ev == null || ev.resources == null) {
|
||||
return [];
|
||||
}
|
||||
List<EnvironmentVariable> envVariables = [];
|
||||
if (ev.resources!.length > 0) {
|
||||
for (var envvar in ev.resources!) {
|
||||
envVariables.add(envvar);
|
||||
}
|
||||
}
|
||||
return envVariables;
|
||||
}
|
||||
|
||||
List<(String?, Resource)> getRequestsFromInsomniaResource(Resource? resource) {
|
||||
if (resource == null) {
|
||||
return [];
|
||||
}
|
||||
List<(String?, Resource)> requests = [];
|
||||
if (resource.type != null || resource.type == 'request') {
|
||||
requests.add((resource.name, resource));
|
||||
} else {
|
||||
print('Resource type is not request');
|
||||
}
|
||||
return requests;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user