Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
test: add complex folder structure test
Browse files Browse the repository at this point in the history
  • Loading branch information
joolfe committed Mar 27, 2021
1 parent 48d7952 commit 56d00df
Show file tree
Hide file tree
Showing 4 changed files with 643 additions and 27 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ async function postmanToOpenApi (input, output, { info = {}, defaultTag = 'defau
for (let [i, element] of items.entries()) {
while (element.item != null) { // is a folder
const { item, name, description: tagDesc } = element
const tagged = item.map(e => ({ ...e, tag: element.tag ? element.tag + ' > ' + name : name }))
tags[element.tag ? element.tag + ' > ' + name : name] = tagDesc
const tag = element.tag ? element.tag + ' > ' + name : name
const tagged = item.map(e => ({ ...e, tag }))
tags[tag] = tagDesc
items.splice(i, 1, ...tagged)
element = tagged.shift()
}
Expand Down Expand Up @@ -51,7 +52,6 @@ async function postmanToOpenApi (input, output, { info = {}, defaultTag = 'defau
...parseTags(tags),
paths
}

const openApiYml = dump(openApi, { skipInvalid: true })
if (output != null) {
await writeFile(output, openApiYml, 'utf8')
Expand Down
265 changes: 253 additions & 12 deletions test/resources/input/v2/FolderCollection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "4adefe15-8b43-49c5-9336-5a5296a26592",
"_postman_id": "50982ed9-0e90-4184-94cf-e50b04ee89d0",
"name": "Folder Collection",
"description": "Just a simple collection for test",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
Expand Down Expand Up @@ -43,7 +43,8 @@
"type": "text/javascript",
"exec": [
""
]
],
"id": "d3b8972e-0cc2-4a26-90bd-49db6835619d"
}
},
{
Expand All @@ -52,10 +53,13 @@
"type": "text/javascript",
"exec": [
""
]
],
"id": "f6ab3c29-34fe-4008-b2c4-4876da6efde6"
}
}
]
],
"protocolProfileBehavior": {},
"_postman_isSubFolder": true
},
{
"name": "Create a user",
Expand Down Expand Up @@ -104,7 +108,8 @@
"type": "text/javascript",
"exec": [
""
]
],
"id": "690b89a6-6168-44d7-bdec-739c871e2764"
}
},
{
Expand All @@ -113,10 +118,12 @@
"type": "text/javascript",
"exec": [
""
]
],
"id": "9b7aa8f8-c6e8-4e7a-a7f4-b8279330a9d7"
}
}
]
],
"protocolProfileBehavior": {}
},
{
"name": "Posts",
Expand Down Expand Up @@ -155,7 +162,8 @@
"type": "text/javascript",
"exec": [
""
]
],
"id": "62d0cff3-700f-40d5-acf9-1a290d7ce47e"
}
},
{
Expand All @@ -164,10 +172,13 @@
"type": "text/javascript",
"exec": [
""
]
],
"id": "9c822236-1954-440f-a5ab-c12d3b9322cc"
}
}
]
],
"protocolProfileBehavior": {},
"_postman_isSubFolder": true
},
{
"name": "Create a post",
Expand All @@ -193,6 +204,232 @@
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
],
"id": "be6e2c57-1240-4c19-b92d-f1acdc5b2a7b"
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
],
"id": "a76eb8d4-26cd-4cda-8246-fd297e0a440b"
}
}
],
"protocolProfileBehavior": {}
},
{
"name": "Folder 1",
"item": [
{
"name": "Folder 2",
"item": [
{
"name": "Folder 3",
"item": [
{
"name": "Folder 4",
"item": [
{
"name": "Folder 5",
"item": [
{
"name": "Request 4",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"example\": \"field\",\n \"other\": {\n \"data1\": \"yes\",\n \"data2\": \"no\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "https://api.io/req4",
"description": "This is a post request with json body"
},
"response": []
}
],
"description": "Folder 5 description",
"event": [
{
"listen": "prerequest",
"script": {
"id": "561f18b6-84ca-4fa1-b999-dca070fcf1ba",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "63640ff7-b4d0-4e0a-a5fa-489f5e0412fb",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"protocolProfileBehavior": {},
"_postman_isSubFolder": true
}
],
"description": "Folder 4 description",
"event": [
{
"listen": "prerequest",
"script": {
"id": "3074ecdc-d10e-41a3-9e5b-d14b2534e7ea",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "04e19b94-8a82-49a5-9d15-dc5a84fc86c7",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"protocolProfileBehavior": {},
"_postman_isSubFolder": true
},
{
"name": "Request 3",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"example\": \"field\",\n \"other\": {\n \"data1\": \"yes\",\n \"data2\": \"no\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "https://api.io/req3",
"description": "This is a post request with json body"
},
"response": []
}
],
"description": "Folder 3 description",
"event": [
{
"listen": "prerequest",
"script": {
"id": "f1d6847d-907c-426c-a65f-5264be44f566",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "17dea697-f594-4392-91d9-58364d831920",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"protocolProfileBehavior": {},
"_postman_isSubFolder": true
},
{
"name": "Request 2",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"example\": \"field\",\n \"other\": {\n \"data1\": \"yes\",\n \"data2\": \"no\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "https://api.io/req2",
"description": "This is a post request with json body"
},
"response": []
}
],
"description": "Folder 2 description",
"event": [
{
"listen": "prerequest",
"script": {
"id": "67fe5742-01b5-4d70-bdff-f7cac5ef01a8",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "b712ac41-73c3-42ce-9ae4-c4d5e52acf02",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"protocolProfileBehavior": {},
"_postman_isSubFolder": true
},
{
"name": "Request 1",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"example\": \"field\",\n \"other\": {\n \"data1\": \"yes\",\n \"data2\": \"no\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "https://api.io/req1",
"description": "This is a post request with json body"
},
"response": []
}
],
"description": "Folder 1 description",
"event": [
{
"listen": "prerequest",
"script": {
"id": "68b3bfe6-524b-4cbb-bcdd-d07f86958ea0",
"type": "text/javascript",
"exec": [
""
Expand All @@ -202,13 +439,15 @@
{
"listen": "test",
"script": {
"id": "8e5fe15c-6a6c-4d46-8a40-3a1e423da8ba",
"type": "text/javascript",
"exec": [
""
]
}
}
]
],
"protocolProfileBehavior": {}
},
{
"name": "Create a info",
Expand All @@ -231,8 +470,10 @@
],
"variable": [
{
"id": "11cfd6e6-21ce-4ae4-8836-f1e5a6d43f14",
"key": "version",
"value": "2.3.0"
}
]
],
"protocolProfileBehavior": {}
}
Loading

0 comments on commit 56d00df

Please sign in to comment.