From 805b0a9387dff044cc73210f969e9458f373a870 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Thu, 26 Dec 2024 05:13:39 +0530 Subject: [PATCH] Add postman utilities --- packages/postman/lib/postman.dart | 1 + packages/postman/lib/utils/postman_utils.dart | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 packages/postman/lib/utils/postman_utils.dart 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; +}