From 4d7424c599c6385e607be736f0e9952bb40708cc Mon Sep 17 00:00:00 2001 From: Jorge Date: Sat, 17 Sep 2022 11:06:33 +0200 Subject: [PATCH 1/3] fix: close #216, an error when there exist an empty folder at the end of the collection --- lib/index.js | 41 ++++++++++--------- test/resources/input/v2/FolderCollection.json | 5 +++ .../resources/input/v21/FolderCollection.json | 5 +++ test/resources/output/Folders.yml | 1 + test/resources/output/FoldersNoConcat.yml | 1 + test/resources/output/FoldersSeparator.yml | 1 + 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/lib/index.js b/lib/index.js index e858597..543b52c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -26,7 +26,7 @@ async function postmanToOpenApi (input, output, { const securitySchemes = {} for (let [i, element] of items.entries()) { - while (element.item != null) { // is a folder + while (element != null && element.item != null) { // is a folder const { item, description: tagDesc } = element const tag = calculateFolderTag(element, folders) const tagged = item.map(e => ({ ...e, tag })) @@ -35,24 +35,27 @@ async function postmanToOpenApi (input, output, { // Empty folders will have tagged empty element = (tagged.length > 0) ? tagged.shift() : items[i] } - const { - request: { url, method, body, description: rawDesc, header, auth }, - name: summary, tag = defaultTag, event: events, response - } = element - const { path, query, protocol, host, port, valid, pathVars } = scrapeURL(url) - if (valid) { - domains.add(calculateDomains(protocol, host, port)) - const joinedPath = calculatePath(path, pathDepth) - if (!paths[joinedPath]) paths[joinedPath] = {} - const { description, paramsMeta } = descriptionParse(rawDesc) - paths[joinedPath][method.toLowerCase()] = { - tags: [tag], - summary, - ...(description ? { description } : {}), - ...parseBody(body, method), - ...parseOperationAuth(auth, securitySchemes, optsAuth), - ...parseParameters(query, header, joinedPath, paramsMeta, pathVars), - ...parseResponse(response, events, responseHeaders) + // If there are an empty folder at the end of the colection elements could be `undefined` + if (element != null) { + const { + request: { url, method, body, description: rawDesc, header, auth }, + name: summary, tag = defaultTag, event: events, response + } = element + const { path, query, protocol, host, port, valid, pathVars } = scrapeURL(url) + if (valid) { + domains.add(calculateDomains(protocol, host, port)) + const joinedPath = calculatePath(path, pathDepth) + if (!paths[joinedPath]) paths[joinedPath] = {} + const { description, paramsMeta } = descriptionParse(rawDesc) + paths[joinedPath][method.toLowerCase()] = { + tags: [tag], + summary, + ...(description ? { description } : {}), + ...parseBody(body, method), + ...parseOperationAuth(auth, securitySchemes, optsAuth), + ...parseParameters(query, header, joinedPath, paramsMeta, pathVars), + ...parseResponse(response, events, responseHeaders) + } } } } diff --git a/test/resources/input/v2/FolderCollection.json b/test/resources/input/v2/FolderCollection.json index 9e8cf20..3f9090e 100644 --- a/test/resources/input/v2/FolderCollection.json +++ b/test/resources/input/v2/FolderCollection.json @@ -471,6 +471,11 @@ "url": "https://api.io/info" }, "response": [] + }, + { + "name": "Empty Folder 2", + "item": [], + "protocolProfileBehavior": {} } ], "variable": [ diff --git a/test/resources/input/v21/FolderCollection.json b/test/resources/input/v21/FolderCollection.json index 27d0427..495d7f5 100644 --- a/test/resources/input/v21/FolderCollection.json +++ b/test/resources/input/v21/FolderCollection.json @@ -575,6 +575,11 @@ } }, "response": [] + }, + { + "name": "Empty Folder 2", + "item": [], + "protocolProfileBehavior": {} } ], "variable": [ diff --git a/test/resources/output/Folders.yml b/test/resources/output/Folders.yml index ef4de01..b7fa438 100644 --- a/test/resources/output/Folders.yml +++ b/test/resources/output/Folders.yml @@ -25,6 +25,7 @@ tags: - name: Folder 1 > Folder 2 > Folder 3 > Folder 4 > Folder 5 description: Folder 5 description - name: Empty Folder + - name: Empty Folder 2 paths: /users/admin/roles: get: diff --git a/test/resources/output/FoldersNoConcat.yml b/test/resources/output/FoldersNoConcat.yml index 9afadc9..68d08fc 100644 --- a/test/resources/output/FoldersNoConcat.yml +++ b/test/resources/output/FoldersNoConcat.yml @@ -23,6 +23,7 @@ tags: - name: Folder 5 description: Folder 5 description - name: Empty Folder + - name: Empty Folder 2 paths: /users/admin/roles: get: diff --git a/test/resources/output/FoldersSeparator.yml b/test/resources/output/FoldersSeparator.yml index 0674233..149e382 100644 --- a/test/resources/output/FoldersSeparator.yml +++ b/test/resources/output/FoldersSeparator.yml @@ -25,6 +25,7 @@ tags: - name: Folder 1-Folder 2-Folder 3-Folder 4-Folder 5 description: Folder 5 description - name: Empty Folder + - name: Empty Folder 2 paths: /users/admin/roles: get: From 09f02d0bcdf61e427ba13d1d1b684523dc842901 Mon Sep 17 00:00:00 2001 From: Jorge Date: Sat, 17 Sep 2022 11:08:29 +0200 Subject: [PATCH 2/3] build: version updated --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9a1f085..12fa425 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "postman-to-openapi", - "version": "2.6.0", + "version": "2.6.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "postman-to-openapi", - "version": "2.6.0", + "version": "2.6.1", "license": "MIT", "dependencies": { "commander": "^8.3.0", diff --git a/package.json b/package.json index ae4c952..5dcb990 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postman-to-openapi", - "version": "2.6.0", + "version": "2.6.1", "description": "Convert postman collection to OpenAPI spec", "main": "lib/index.js", "types": "types/index.d.ts", From 2d5ececb7e2936afa8bc109732f16022c3fd9871 Mon Sep 17 00:00:00 2001 From: Jorge Date: Sat, 17 Sep 2022 11:10:08 +0200 Subject: [PATCH 3/3] docs: update changelog --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8b8691..132ba9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +### [2.6.1](https://github.com/joolfe/postman-to-openapi/compare/2.6.0...2.6.1) (2022-09-17) + + +### Bug Fixes + +* close [#216](https://github.com/joolfe/postman-to-openapi/issues/216), an error when there exist an empty folder at the end of the collection ([4d7424c](https://github.com/joolfe/postman-to-openapi/commit/4d7424c599c6385e607be736f0e9952bb40708cc)) + + +### Build System + +* version updated ([09f02d0](https://github.com/joolfe/postman-to-openapi/commit/09f02d0bcdf61e427ba13d1d1b684523dc842901)) + ## [2.6.0](https://github.com/joolfe/postman-to-openapi/compare/2.5.0...2.6.0) (2022-08-29)