Add postman utilities

This commit is contained in:
Ashita Prasad
2024-12-26 05:13:39 +05:30
parent 0d9eb13010
commit 805b0a9387
2 changed files with 34 additions and 0 deletions

View File

@ -1,3 +1,4 @@
library postman;
export 'models/models.dart';
export 'utils/postman_utils.dart';

View File

@ -0,0 +1,33 @@
import '../models/postman_collection.dart';
List<(String?, Request)> getRequestsFromPostmanCollection(
PostmanCollection? pc) {
if (pc == null || pc.item == null) {
return [];
}
List<(String?, Request)> requests = [];
if (pc.item!.length > 0) {
for (var i in pc.item!) {
requests.addAll(getRequestsFromPostmanItem(i));
}
}
return requests;
}
List<(String?, Request)> getRequestsFromPostmanItem(Item? item) {
if (item == null) {
return [];
}
List<(String?, Request)> requests = [];
if (item.request != null) {
requests.add((item.name, item.request!));
} else {
if (item.item != null && item.item!.length > 0) {
for (var i in item.item!) {
var r = getRequestsFromPostmanItem(i);
requests.addAll(r);
}
}
}
return requests;
}