@@ -286,15 +286,18 @@ function buildOas3UrlWithContext(ourUrl = '', contextUrl = '') {
286286 const computedScheme = stripNonAlpha ( parsedUrl . protocol ) || stripNonAlpha ( parsedContextUrl . protocol ) || ''
287287 const computedHost = parsedUrl . host || parsedContextUrl . host
288288 const computedPath = parsedUrl . pathname || ''
289+ let res
289290
290291 if ( computedScheme && computedHost ) {
291- const res = `${ computedScheme } ://${ computedHost + computedPath } `
292+ res = `${ computedScheme } ://${ computedHost + computedPath } `
292293
293294 // If last character is '/', trim it off
294- return res [ res . length - 1 ] === '/' ? res . slice ( 0 , - 1 ) : res
295+ }
296+ else {
297+ res = computedPath
295298 }
296299
297- return ''
300+ return res [ res . length - 1 ] === '/' ? res . slice ( 0 , - 1 ) : res
298301}
299302
300303function getVariableTemplateNames ( str ) {
@@ -317,13 +320,17 @@ function swagger2BaseUrl({spec, scheme, contextUrl = ''}) {
317320 const computedScheme = scheme || firstSchemeInSpec || stripNonAlpha ( parsedContextUrl . protocol ) || 'http'
318321 const computedHost = spec . host || parsedContextUrl . host || ''
319322 const computedPath = spec . basePath || ''
323+ let res
320324
321325 if ( computedScheme && computedHost ) {
322- const res = `${ computedScheme } ://${ computedHost + computedPath } `
323-
324- // If last character is '/', trim it off
325- return res [ res . length - 1 ] === '/' ? res . slice ( 0 , - 1 ) : res
326+ // we have what we need for an absolute URL
327+ res = `${ computedScheme } ://${ computedHost + computedPath } `
328+ }
329+ else {
330+ // if not, a relative URL will have to do
331+ res = computedPath
326332 }
327333
328- return ''
334+ // If last character is '/', trim it off
335+ return res [ res . length - 1 ] === '/' ? res . slice ( 0 , - 1 ) : res
329336}
0 commit comments