diff --git a/packages/postman/lib/postman.dart b/packages/postman/lib/postman.dart index 25f6204b..a2e1cc58 100644 --- a/packages/postman/lib/postman.dart +++ b/packages/postman/lib/postman.dart @@ -1,3 +1,4 @@ library postman; export 'models/models.dart'; +export 'utils/postman_utils.dart'; diff --git a/packages/postman/lib/utils/postman_utils.dart b/packages/postman/lib/utils/postman_utils.dart new file mode 100644 index 00000000..10301049 --- /dev/null +++ b/packages/postman/lib/utils/postman_utils.dart @@ -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; +}