Skip to content

Commit

Permalink
Merge pull request #219 from joolfe/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
joolfe authored Sep 17, 2022
2 parents 490d2cc + 2d5ecec commit 72b6bd1
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 22 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
41 changes: 22 additions & 19 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
Expand All @@ -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)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions test/resources/input/v2/FolderCollection.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@
"url": "https://api.io/info"
},
"response": []
},
{
"name": "Empty Folder 2",
"item": [],
"protocolProfileBehavior": {}
}
],
"variable": [
Expand Down
5 changes: 5 additions & 0 deletions test/resources/input/v21/FolderCollection.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@
}
},
"response": []
},
{
"name": "Empty Folder 2",
"item": [],
"protocolProfileBehavior": {}
}
],
"variable": [
Expand Down
1 change: 1 addition & 0 deletions test/resources/output/Folders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions test/resources/output/FoldersNoConcat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tags:
- name: Folder 5
description: Folder 5 description
- name: Empty Folder
- name: Empty Folder 2
paths:
/users/admin/roles:
get:
Expand Down
1 change: 1 addition & 0 deletions test/resources/output/FoldersSeparator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 72b6bd1

Please sign in to comment.