File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -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 ) {
Original file line number Diff line number Diff line change @@ -497,6 +497,23 @@ describe('buildRequest - OpenAPI Specification 3.0', function () {
497497
498498 expect ( res ) . toEqual ( 'http://google.com' )
499499 } )
500+ it ( 'should create a relative url based on a relative server if no contextUrl is available' , function ( ) {
501+ const spec = {
502+ openapi : '3.0.0' ,
503+ servers : [
504+ {
505+ url : '/mypath'
506+ }
507+ ]
508+ }
509+
510+ const res = baseUrl ( {
511+ spec,
512+ server : '/mypath'
513+ } )
514+
515+ expect ( res ) . toEqual ( '/mypath' )
516+ } )
500517 it ( 'should return an empty string if no servers or contextUrl are provided' , function ( ) {
501518 const spec = {
502519 openapi : '3.0.0'
You can’t perform that action at this time.
0 commit comments