Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: import hopp collection (#2824)

Nivedinc99797bcef06
diff --git a/packages/hoppscotch-app/src/helpers/import-export/import/hopp.ts b/packages/hoppscotch-app/src/helpers/import-export/import/hopp.ts
index d8f7f84d3..259ea59be 100644
--- a/packages/hoppscotch-app/src/helpers/import-export/import/hopp.ts
+++ b/packages/hoppscotch-app/src/helpers/import-export/import/hopp.ts
@@ -33,12 +33,7 @@ export default defineImporter({
O.chain(
flow(
makeCollectionsArray,
- RA.map(
- flow(
- O.fromPredicate(isValidCollection),
- O.map(translateToNewRESTCollection)
- )
- ),
+ RA.map(validateCollection),
O.sequenceArray,
O.map(RA.toArray)
)
@@ -61,6 +56,18 @@ const isValidCollection = (
): collection is HoppCollection<HoppRESTRequest> =>
isPlainObject(collection) && "v" in collection
+/**
+ * checks if a collection is a valid hoppscotch collection.
+ * else translate it into one.
+ */
+const validateCollection = (collection: unknown) => {
+ if (isValidCollection(collection)) {
+ return O.some(collection)
+ } else {
+ return O.some(translateToNewRESTCollection(collection))
+ }
+}
+
/**
* convert single collection object into an array so it can be handled the same as multiple collections
*/