@@ -213,16 +213,13 @@ export function baseUrl(obj) {
213213 return specIsOAS3 ? oas3BaseUrl ( obj ) : swagger2BaseUrl ( obj )
214214}
215215
216- function oas3BaseUrl ( { spec, server, serverVariables = { } } ) {
216+ function oas3BaseUrl ( { spec, server, contextUrl, serverVariables = { } } ) {
217+ console . log ( 'hello' )
217218 const servers = spec . servers
218219
219220 let selectedServerUrl = ''
220221 let selectedServerObj = null
221222
222- if ( ! servers || ! Array . isArray ( servers ) ) {
223- return ''
224- }
225-
226223 if ( server ) {
227224 const serverUrls = servers . map ( srv => srv . url )
228225
@@ -232,7 +229,7 @@ function oas3BaseUrl({spec, server, serverVariables = {}}) {
232229 }
233230 }
234231
235- if ( ! selectedServerUrl ) {
232+ if ( ! selectedServerUrl && servers ) {
236233 // default to the first server if we don't have one by now
237234 selectedServerUrl = servers [ 0 ] . url
238235 selectedServerObj = servers [ 0 ]
@@ -253,7 +250,25 @@ function oas3BaseUrl({spec, server, serverVariables = {}}) {
253250 } )
254251 }
255252
256- return selectedServerUrl
253+ return buildOas3UrlWithContext ( selectedServerUrl , contextUrl )
254+ }
255+
256+ function buildOas3UrlWithContext ( ourUrl = '' , contextUrl = '' ) {
257+ const parsedUrl = url . parse ( ourUrl )
258+ const parsedContextUrl = url . parse ( contextUrl )
259+
260+ const computedScheme = stripNonAlpha ( parsedUrl . protocol ) || stripNonAlpha ( parsedContextUrl . protocol ) || ''
261+ const computedHost = parsedUrl . host || parsedContextUrl . host
262+ const computedPath = parsedUrl . pathname || ''
263+
264+ if ( computedScheme && computedHost ) {
265+ const res = `${ computedScheme } ://${ computedHost + computedPath } `
266+
267+ // If last character is '/', trim it off
268+ return res [ res . length - 1 ] === '/' ? res . slice ( 0 , - 1 ) : res
269+ }
270+
271+ return ''
257272}
258273
259274function getVariableTemplateNames ( str ) {
0 commit comments