Skip to content

Commit 848f10f

Browse files
authored
Merge pull request #1160 from shockey/bug/ui-3791-oas3-baseurl-typeerror
OAS3 baseUrl TypeError
2 parents 705812c + 008da0e commit 848f10f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/execute/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function oas3BaseUrl({spec, server, contextUrl, serverVariables = {}}) {
219219
let selectedServerUrl = ''
220220
let selectedServerObj = null
221221

222-
if (server) {
222+
if (server && servers) {
223223
const serverUrls = servers.map(srv => srv.url)
224224

225225
if (serverUrls.indexOf(server) > -1) {

test/oas3/execute/main.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,5 +484,30 @@ describe('buildRequest - OpenAPI Specification 3.0', function () {
484484

485485
expect(res).toEqual('https://petstore.com')
486486
})
487+
it('should fall back to contextUrls if no servers are provided', function () {
488+
const spec = {
489+
openapi: '3.0.0'
490+
}
491+
492+
const res = baseUrl({
493+
spec,
494+
server: 'http://some-invalid-server.com/',
495+
contextUrl: 'http://google.com/'
496+
})
497+
498+
expect(res).toEqual('http://google.com')
499+
})
500+
it('should return an empty string if no servers or contextUrl are provided', function () {
501+
const spec = {
502+
openapi: '3.0.0'
503+
}
504+
505+
const res = baseUrl({
506+
spec,
507+
server: 'http://some-invalid-server.com/'
508+
})
509+
510+
expect(res).toEqual('')
511+
})
487512
})
488513
})

0 commit comments

Comments
 (0)