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

Commit

Permalink
feat: support postman collection v2
Browse files Browse the repository at this point in the history
Close #20
  • Loading branch information
joolfe committed Oct 1, 2020
1 parent c3b297c commit 1d9da47
Show file tree
Hide file tree
Showing 32 changed files with 1,526 additions and 174 deletions.
18 changes: 17 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ async function postmanToOpenApi (input, output, { info = {}, defaultTag = 'defau
element = tagged.shift()
}
const {
request: { url: { path, query, protocol, host }, method, body, description: rawDesc, header },
request: { url, method, body, description: rawDesc, header },
name: summary, tag = defaultTag, event: events
} = element
const { path, query, protocol, host } = scrapeURL(url)
domains.add(calculateDomains(protocol, host))
const joinedPath = calculatePath(path, pathDepth)
if (!paths[joinedPath]) paths[joinedPath] = {}
Expand Down Expand Up @@ -250,6 +251,21 @@ function calculateDomains (protocol, hosts) {
return protocol + '://' + hosts.join('.')
}

/** Support for collection V2 */
function scrapeURL (url) {
if (typeof url === 'string' || url instanceof String) {
const objUrl = new URL(url)
return {
raw: url,
path: decodeURIComponent(objUrl.pathname).slice(1).split('/'),
query: [],
protocol: objUrl.protocol.slice(0, -1),
host: decodeURIComponent(objUrl.hostname).split('.')
}
}
return url
}

/* Parse domains from operations or options */
function parseServers (domains, serversOpts) {
let servers
Expand Down
Loading

0 comments on commit 1d9da47

Please sign in to comment.