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

Commit

Permalink
Merge branch 'release/v0.8.0' into fix-#36/raise-error-if-none-of-ser…
Browse files Browse the repository at this point in the history
…ver-or-host-is-defined
  • Loading branch information
derevnjuk authored Jul 10, 2020
2 parents 75a5ee3 + 17fa8e2 commit 714780c
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,15 @@ const getPayload = (swagger, path, method) => {
* @returns {string[]}
*/
const parseUrls = (swagger) => {
if (Array.isArray(swagger.servers) && swagger.servers.length) {
return swagger.servers.map((server) => removeTrailingSlash(server.url))
}

if (swagger.host) {
if (!Array.isArray(swagger.servers)) {
const basePath =
typeof swagger.basePath !== 'undefined' ? removeLeadingSlash(swagger.basePath) : ''
const host = removeTrailingSlash(swagger.host)
const schemes = typeof swagger.schemes !== 'undefined' ? swagger.schemes : ['https']
return schemes.map((x) => x + '://' + removeTrailingSlash(host + '/' + basePath))
}

return []
return swagger.servers.map((server) => removeTrailingSlash(server.url))
}

/**
Expand All @@ -178,10 +174,6 @@ const parseUrls = (swagger) => {
const getBaseUrl = (swagger) => {
const urls = parseUrls(swagger)

if (!Array.isArray(urls) || !urls.length) {
throw new Error('None server or host is defined.')
}

let preferredUrls = urls.filter((x) => x.startsWith('https') || x.startsWith('wss'))

if (!preferredUrls.length) {
Expand Down

0 comments on commit 714780c

Please sign in to comment.